Announcement

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

  • Adding confidence intervals to a two-way line graph

    Dear all,

    I think this an easy question but I got stuck.

    For a seminal replication study, I would like to plot a line graph showing the means of my variable of interest and combine this with the confidence intervals.
    I can use ciplot, ci and statsby, but I am quite uncommon with both latter commands.
    I also found the option of adding a rcap graph, but I haven't figured out, how to compute the high and low values the confidence level (95%) of each observation (mean) of my variable in time as I am working with panel data.

    The code is the following:

    Code:
     // Figure 3
    by syear T1, sort: egen meannoabs = mean(leadnoabs)
    * without rap
    twoway (line meannoabs syear if T1 == 1 & syear!=1996) (line meannoabs syear if T1 == 0 & syear!=1996) , legend(order(1 "Treatment" 2 "Control")) scheme(sj) name(graph3a, replace)
    
    gen hi = meannoabs+1.96*se(meannoabs)
    gen lo = meannoabs-1.96*se(meannoabs)
    
    * just rcap CI
    twoway (rcap meannoabs hi lo if T1==1) (rcap meannoabs hi lo if T1==0)
    
    * combined 
    twoway (line meannoabs syear if T1 == 1 & syear!=1996) (line meannoabs syear if T1 == 0 & syear!=1996) (rcap meannoabs hi lo if T1==1) (rcap meannoabs hi lo if T1==0), legend(order(1 "Treatment" 2 "Control")) scheme(sj) 
    
    *graph export
    T1 is the treatment dummy (0 = control, 1=treated). I know that ciplot stores upper and lower values as scalars. My main problem is working with panel data, as I need for every year the CI...

    I am using Stata 15.1

    Thank you very much in advance.

    Aline


  • #2
    Try something like:

    Code:
     twoway (line meannoabs syear) (rcap lo hi syear)
    Best regards,

    Marcos

    Comment

    Working...
    X