Graph evolution of quantile non-linear coefficient: can it be done with grqreg? Other options?

1.9k Views Asked by At

I have the following model:

Y_{it} = alpha_i + B1*weight_{it} + B2*Dummy_Foreign_{i} + B3*(weight*Dummy_Foreign)_ {it} + e_{it}

and I am interested on the effect on Y of weight for foreign cars and to graph the evolution of the relevant coefficient across quantiles, with the respective standard errors. That is, I need to see the evolution of the coefficients (B1+ B3). I know this is a non-linear effect, and would require some sort of delta method to obtain the variance-covariance matrix to obtain the standard error of (B1+B3).

Before I delve into writing a program that attempts to do this, I thought I would try and ask if there is a way of doing it with grqreg. If this is not possible with grqreg, would someone please guide me into how they would start writing a code that computes the proper standard errors, and graphs the quantile coefficient.

For a cross section example of what I am trying to do, please see code below.

  1. I use grqred to generate the evolution of the separate coefficients (but I need the joint one)-- One graph for the evolution of (B1+B3) with it's respective standard errors.

Thanks. Effect of weight and weight interacted with foreign dummy variable.

(I am using Stata 14.1 on Windows 10):

clear
sysuse auto
set scheme s1color

gen gptm = 1000/mpg
label var gptm "gallons / 1000 miles"

gen weight_foreign= weight*foreign
label var weight_foreign "Interaction weight and foreign car"

qreg gptm weight foreign weight_foreign , q(.5) 
grqreg  weight weight_foreign , ci ols olsci reps(40)  

*** Question 1: How to constuct the plot of the coefficient of interest?
1

There are 1 best solutions below

0
On BEST ANSWER

Your second question is off-topic here since it is statistical. Try the CV SE site or Statalist.

Here's how you might do (1) in a cross section, using margins and marginsplot:

clear
set more off
sysuse auto
set scheme s1color
gen gptm = 1000/mpg
label var gptm "gallons / 1000 miles"
sqreg gptm c.weight##i.foreign, q(10 25 50 75 95) reps(500) coefl
margins, dydx(weight) predict(outcome(q10)) predict(outcome(q25)) predict(outcome(q50)) predict(outcome(q75)) predict(outcome(q95)) at(foreign=(0 1)) 
marginsplot, xdimension(_predict) xtitle("Quantile") ///
legend(label(1 "Domestic") label(2 "Foreign")) ///
xlabel(none) xlabel(1 "Q10" 2 "Q25" 3 "Q50" 4 "Q75" 5 "Q95", add) ///
title("Marginal Effect of Weight By Origin") ///
ytitle("GPTM")

This produces a graph like this:

enter image description here

I didn't recast the CI here since it would look cluttered, but that would make it look more like your graph. Just add recastci(rarea) to the options.

Unfortunately, none of the panel quantile regression commands play nice with factor variables and margins. But we can hack something together. First, you can calculate the sums of coefficients with nlcom (instead of more natural lincom, which the lacks the post option), store them, and use Ben Jann's coefplot to graph them. Here's a toy example to give you the main idea where we will look at the effect of tenure for union members:

set more off
estimates clear
webuse nlswork, clear
gen tXu = tenure*union
local quantiles 1 5 10 25 50 75 90 95 99    // K quantiles that you care about
local models ""                             // names of K quantile models for coefplot to graph 
local xlabel ""                             // for x-axis labels
local j=1                                   // counter for quantiles
foreach q of numlist `quantiles' {
    qregpd ln_wage tenure union tXu, id(idcode) fix(year) quantile(`q')
    nlcom (me_tu:_b[tenure]+_b[tXu]), post
    estimates store me_tu`q'
    local models `"`models' me_tu`q' || "'
    local xlabel `"`xlabel' `j++' "Q{sub:`q'}""'
}
di "`models'
di `"`xlabel'"'
coefplot `models' /// 
, vertical bycoefs rescale(100) ///
xlab(none) xlabel(`xlabel', add) ///
title("Marginal Effect of Tenure for Union Members On Each Conditional Quantile Q{sub:{&tau}}", size(medsmall)) ///
ytitle("Wage Change in Percent" "") yline(0) ciopts(recast(rcap))

This makes a dromedary curve, which suggests that the effect of tenure is larger in the middle of the wage distribution than at the tails:

enter image description here