Hi all,
I am conducting heterogeneity analysis and presenting the results using coefplot. I have two sets of regressors and several heterogeneity groups.
I would like to add the p-values to the plot, showing which coefficient estimates are statistically different. However, with the divided coefplot, the same p-values show up on both sides---but I would like to include different p-values on the right and the left side. I am including the output I am currently getting -- as you can see, the same p-values are added on both the right and left side so that they are currently one on top of the other. I am also including STATA code that can be run below.
Thank you very much!
OUTPUT:
STATA CODE:
** Load data
use "https://www.stata-press.com/data/r18/auto", clear
** Create binary variables for heterogeneity
foreach var of varlist weight length trunk turn mpg displacement{
sum `var', det
g high_`var'=`var'>`r(p50)'
}
** Do this for two x variables
foreach group in mpg displacement{
** And for four heterogeneity variables
foreach het in weight length trunk turn{
** And for each level of the heterogeneity variable
forval h=0/1{
** Create x regressor
cap drop reg_`het'
g reg_`het'=high_`group'
** Run regression
qui: eststo reg`h': reg price reg_`het' if high_`het'==`h'
** Score coefficient estimate
scalar e_`het'_`h'=_b[reg_`het']
est store e_`group'`het'_`h'
}
** Test whether coefficient estimates are significantly different from each other in the two heterogeneity levels
suest reg0 reg1
test [reg0_mean]reg_`het' - [reg1_mean]reg_`het' = 0
** Store the p-value
local pval=`r(p)'
local p`group'`het': display %4.3f `pval'
}
}
* Output the coefficient plot
coefplot (e_mpgweight_0 e_mpglength_0 e_mpgtrunk_0 e_mpgturn_0, label(<= Median, size(vlarge)) ciopts(color(red)) mcolor(red) mfc(red) m(diamond) lcolor(red) text(1 2500 "p=`pmpgweight'")) ///
(e_mpgweight_1 e_mpgtrunk_1 e_mpglength_1 e_mpgturn_1, label(> Median) ciopts(color(black) lp(dash)) mcolor(black) mfc(black) text(2 2500 "p=`pmpglength'") ///
text(3 2500 "p=`pmpgtrunk'") text(4 2500 "p=`pmpgturn'")), bylabel({it: MPG}) ///
|| (e_displacementweight_0 e_displacementlength_0 e_displacementtrunk_0 e_displacementturn_0, label(<= Median) ciopts(color(red)) mcolor(red) mfc(red) m(diamond) lcolor(red)) ///
(e_displacementweight_1 e_displacementlength_1 e_displacementtrunk_1 e_displacementturn_1, label(> Median) ciopts(color(black) lp(dash)) mcolor(black) mfc(black) ///
text(1 2500 "p=`pdisplacementweight'") text(2 2500 "p=`pdisplacementlength'") text(3 2500 "p=`pdisplacementtrunk'") text(4 2500 "p=`pdisplacementturn'")), bylabel({it: Displacement}) ///
||, keep(reg_weight reg_length reg_trunk reg_turn) coeflabels(reg_weight = "Weight" reg_length = "Length" reg_turn = "Turn" reg_trunk = "Trunk", labsize(medlarge)) ///
xline(0, lcolor(black)) yline(1.5 2.5 3.5 4.5, lcolor(black)) hor graphregion(color(white)) bgcol(white) byopts(xrescale) name(coefplot, replace) xtitle("Coefficient on {it: Y}")
I am conducting heterogeneity analysis and presenting the results using coefplot. I have two sets of regressors and several heterogeneity groups.
I would like to add the p-values to the plot, showing which coefficient estimates are statistically different. However, with the divided coefplot, the same p-values show up on both sides---but I would like to include different p-values on the right and the left side. I am including the output I am currently getting -- as you can see, the same p-values are added on both the right and left side so that they are currently one on top of the other. I am also including STATA code that can be run below.
Thank you very much!
OUTPUT:
STATA CODE:
** Load data
use "https://www.stata-press.com/data/r18/auto", clear
** Create binary variables for heterogeneity
foreach var of varlist weight length trunk turn mpg displacement{
sum `var', det
g high_`var'=`var'>`r(p50)'
}
** Do this for two x variables
foreach group in mpg displacement{
** And for four heterogeneity variables
foreach het in weight length trunk turn{
** And for each level of the heterogeneity variable
forval h=0/1{
** Create x regressor
cap drop reg_`het'
g reg_`het'=high_`group'
** Run regression
qui: eststo reg`h': reg price reg_`het' if high_`het'==`h'
** Score coefficient estimate
scalar e_`het'_`h'=_b[reg_`het']
est store e_`group'`het'_`h'
}
** Test whether coefficient estimates are significantly different from each other in the two heterogeneity levels
suest reg0 reg1
test [reg0_mean]reg_`het' - [reg1_mean]reg_`het' = 0
** Store the p-value
local pval=`r(p)'
local p`group'`het': display %4.3f `pval'
}
}
* Output the coefficient plot
coefplot (e_mpgweight_0 e_mpglength_0 e_mpgtrunk_0 e_mpgturn_0, label(<= Median, size(vlarge)) ciopts(color(red)) mcolor(red) mfc(red) m(diamond) lcolor(red) text(1 2500 "p=`pmpgweight'")) ///
(e_mpgweight_1 e_mpgtrunk_1 e_mpglength_1 e_mpgturn_1, label(> Median) ciopts(color(black) lp(dash)) mcolor(black) mfc(black) text(2 2500 "p=`pmpglength'") ///
text(3 2500 "p=`pmpgtrunk'") text(4 2500 "p=`pmpgturn'")), bylabel({it: MPG}) ///
|| (e_displacementweight_0 e_displacementlength_0 e_displacementtrunk_0 e_displacementturn_0, label(<= Median) ciopts(color(red)) mcolor(red) mfc(red) m(diamond) lcolor(red)) ///
(e_displacementweight_1 e_displacementlength_1 e_displacementtrunk_1 e_displacementturn_1, label(> Median) ciopts(color(black) lp(dash)) mcolor(black) mfc(black) ///
text(1 2500 "p=`pdisplacementweight'") text(2 2500 "p=`pdisplacementlength'") text(3 2500 "p=`pdisplacementtrunk'") text(4 2500 "p=`pdisplacementturn'")), bylabel({it: Displacement}) ///
||, keep(reg_weight reg_length reg_trunk reg_turn) coeflabels(reg_weight = "Weight" reg_length = "Length" reg_turn = "Turn" reg_trunk = "Trunk", labsize(medlarge)) ///
xline(0, lcolor(black)) yline(1.5 2.5 3.5 4.5, lcolor(black)) hor graphregion(color(white)) bgcol(white) byopts(xrescale) name(coefplot, replace) xtitle("Coefficient on {it: Y}")
Comment