I'm having a problem creating a coefficient plot with Stata that produces vertical lines across the entire x-axis.
The code works fine, but it somehow clusters my coefplot-lines to the left of the x-axis, leaving most of the axis unused.
It is mainly this line of code I am concerned with, which uses some data produced in the loop at the bottom of my text.
Code:
coefplot `all_stores', keep(sibling_1_female) saving(COEFPLOT_ALL_SEPARATELY_`sex', replace) ytitle("") xlabel(`xlabels') xscale(range(1(1)6)) ylabel(-3(1)3) yscale(range(`lower_bound' `upper_bound')) scheme(s2mono) graphregion(color(white)) vertical yline(0) legend(off) //create one coefficient plot for each dataset
Array
What I want it to look like, though, is one vertical line aligned with each of the x-axis labels. So that the first line is above BHPSUKHLS, the second is above CFPS, the third above HILDA, etc.
Does anyone know what I'm missing? Maybe there is an option I should be adding to the coefplot function?
Please let me know if anything is unclear and I will try to provide more detailed information as needed.
Many thanks,
Thomas
Below is the loop that creates the variables/data that's used in the code above
Code:
replace age = . //first, we need to make sure we use the appropriate age variable: we replace age with the respective age variable for each dependent variable !!! replace age = age_risk_tol replace age = age_gamblerisk_tol if age == . replace age = age_finarisk_tol if age == . replace age_squared = age^2 replace age_cubed = age^3 local depvar Z_risk //then, we need to make sure we use the appropriate dependent variable: define the local to equal to the name of the respective dependent variable !!! global depvar Z_risk quietly reg $depvar female if $sample_restrictions , robust quietly ttest $depvar if $sample_restrictions, by(female) global mmean= round(r(mu_1), .001) global wmean= round(r(mu_2), .001) global msd= round(r(sd_1), .001) global wsd= round(r(sd_2), .001) local pval= r(p) global title "Risk Tolerance [0-10] " global summary "Summary statistics of first-borns' $title" global dataset BHPSUKHLS CFPS HILDA IFLS LISS MCS NLSY79 SOEP //must also change the list of datasets for each dependent variable !!! forval i=1/2{ //begin gender loop local sex : word `i' of $gender local j = `i' -1 global Title "First-born `sex''s $title" //all datasets combined in one. quietly reg $depvar sibling_1_female $good_controls if female==`j' & $sample_restrictions, robust est store ALL_`sex' outreg2 using `depvar'_`sex', title(The Effect of Having a Younger Sister on $Title ) ctitle(`sex') stats(coef se ci) paren(se) bracket(ci) bdec(3) sdec(3) cdec(3) adjr2 nocons addtext(Dataset, ALL) nonotes addnote(*** p<0.01 ** p<0.05 * p<0.1. , Robust standard errors in parentheses and confidence intervals in brackets. , "Controlling for subject's age, age spacing between siblings and parents, " , $summary, Men: mean=$mmean stdev=$msd . Women: mean=$wmean stdev=$wsd . DiM p-value=$pval .) replace local lower_bound = ( _b[sibling_1_female] - invttail(e(df_r),0.025)*_se[sibling_1_female] ) *2 //must change 0.025 to another value if not estimated for level(95) local upper_bound = ( _b[sibling_1_female] + invttail(e(df_r),0.025)*_se[sibling_1_female] ) *2 coefplot ALL_`sex', title(The Effect of Having a Younger Sister on $Title ) xtitle("All datasets") keep(sibling_1_female) saving(COEFPLOT_ALL_`sex', replace) ytitle("") yscale(range(`lower_bound' `upper_bound')) scheme(s2mono) graphregion(color(white)) vertical yline(0) legend(off) //for each dataset separately. forval i=1/6{ //begin dataset loop --NOTE: must change the loop counter to equal the amount of datasets used (see dataset list above) local data : word `i' of $dataset quietly reg $depvar sibling_1_female $good_controls if female==`j' & dataset=="`data'" & $sample_restrictions, robust est store `data'_`sex' //stored regression results used for coefplot below outreg2 using `depvar'_`sex', ctitle(`sex') stats(coef se ci) paren(se) bracket(ci) bdec(3) sdec(3) cdec(3) adjr2 nocons addtext(Dataset, `data') append excel //append the output into the same Excel file coefplot `data'_`sex', keep(sibling_1_female) saving(COEFPLOT_`data'_`sex', replace) xtitle("`data'") ytitle("") nolabels yscale(range(`lower_bound' `upper_bound')) scheme(s2mono) graphregion(color(white)) vertical yline(0) legend(off) //create one coefficient plot for each dataset local coefplotcombine "`coefplotcombine' COEFPLOT_`data'_`sex'.gph" local all_stores `all_stores' `data'_`sex' local xlabels `xlabels' `i' "`data'" } //end dataset loop incl controls } //end gender loop
0 Response to coefplot - creating a vertical coefficient plot with multiple lines across the entire x-axis
Post a Comment