Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 'Coefplot' plotting same (name) estimate from different OLS models across three years in a single graph

    Using 'coefplot', I am unable to plot the same estimate from different models across three years without having the estimates bunch up into a single year's plot region. The steps in my code are in the order below:
    1. Estimate the slope coefficient with reghdfe and store them.
    2. Prepare the estimates for 'estab' with 'estfe' and export tables.
    3. Only plot the estimated coefficient on the independent variable for three dependent variables (dv). Each dv has 4 models. Each model is estimated for 3 years. Total 12 estimated coefficients for each of the 3 outcome (subgraph). The models start with the word: reg(for bivariate); C( with controls); P(bivariate placebo sample); C_P(placebo sample with controls).
    4. Unexpected graph output (attached): while the 3 subgraphs in the graph indicate the 3 years beside the Y axis but the estimates are bunched up in 1 year's plot region in each of the subgraphs rather than plotted neatly across all 3 years. The label for each individual year are also overlapping with one another.
    I think the problem lies somewhere in my use of coefplot syntax, specifically the use of parentheses, in calling the same estimated coefficient from several models either after 'coefplot or with 'group' option as I do get the desired plot when I don't plot the 3 years or plot the years horizontally. I am unable to neatly plot the years vertically however.

    Code:
    ***OLS Estimates with Controls (the same is repeated without controls for both sample and placebo sample)***
    foreach v of numlist 91 01 11 {
    if length("`v'") == 1 local v 0`v'
    foreach m of varlist lg`v'light trd`v' lit`v' {
    qui reghdfe `m' k_y_n lg`v'p sc`v' st`v' tdist_500 nrcity_km if pc11_pca_tot_p <10000, absorb(state_district) vce(robust)
    est sto C`m'
    }
    }
    
    ***Prepare estimates for esttab***
    estfe reg* C* P* C_P*, labels(state_district "District_FE")
    
    ***Coefplot***
    coefplot (reglg*light, label(Bivariate) msymbol(oh)) (Clg*light, label(With Controls) msymbol(o)) (Plg*light, label(Bivariate (Placebo)) msymbol(th)) (C_Plg*light, label(With Controls (Placebo)) msymbol(t)), bylabel(Economic Activity) || (regtrd*, label(Bivariate) msymbol(oh)) (Ctrd*, label(With Controls) msymbol(o)) (Ptrd*, label(Bivariate (Placebo)) msymbol(th)) (C_Ptrd*, label(With Controls (Placebo)) msymbol(t)), bylabel(Road) || (reglit*, label(Bivariate) msymbol(oh)) (Clit*, label(With Controls) msymbol(o)) (Plit*, label(Bivariate (Placebo)) msymbol(th)) (C_Plit*, label(With Controls (Placebo)) msymbol(t)), bylabel(Literacy) ||, groups(*91*="{bf:1991}" *01*="{bf:2001}" *11*="{bf:2011}", labsize(tiny)) keep(k_y_n) xline(0, lcolor(black) lwidth(thin) lpattern(dash)) byopts(xrescale) ylabel(none) ytick(none) asequation swapnames mlabposition(1) mlabel(cond(@pval<.05, "*", "")) note("* p < .05")
    Click image for larger version

Name:	Figure 1.png
Views:	0
Size:	0
ID:	1659702
    Last edited by Taha Rauf; 14 Apr 2022, 23:07.

  • #2
    Click image for larger version

Name:	Figure 1.png
Views:	1
Size:	415.7 KB
ID:	1659806


    (Reattaching the image 'Figure 1' here in case it isn't visible in the original post above)

    Comment

    Working...
    X