Announcement

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

  • Calculating top and bottom 2.5%

    Hi everyone,

    I am trying to add 95% confidence intervals to a kdenstiy plot. I think I need to caculate the top 2.5% and bottom 2.5% of my variable b, but I am not sure how to do this and to add it to the plot as lines (line at lower and upper). Any ideas? Thanks!

    Code:
    preserve
    set seed 692525
    tempfile temp  // to hold the results from each repetition
    permute beta1 b = _b[beta1], saving(`temp') reps(10):reghdfe hous_all_act_ind beta1 gender2 race2 age_at_refer if ym>=`=tm(2018m12)', absorb(i.hh_zip2 i.yearmonth)
    su b
    use `temp', clear
    kdensity b, lwidth(0.3) lcolor(cranberry)  xline(-0.027, lwidth(0.3) lcolor(ebblue) lpattern(longdash)) xlabel (-0.03 (.01) 0.005) xtitle(Estimated Placebo Betas) ytitle(Density) title(Housing Risk Services) graphregion(color(white)) bgcolor(white) text(150 -0.015 "Actual Beta = -0.027", size(small)) 
    graph export "placebo1.png", as (png) replace
    restore

  • #2
    You've asked this before. This is clearer to me than the earlier version I read, but please go back and mark the earlier threads as solved with a cross-reference to here-- if this one reaches a solution.

    If I understand this correctly, your variable b contains a sampling distribution of estimates, so you want its 2.5% and 97.5% percentiles.

    Here is an analogue.

    Code:
    . clear
    
    . set seed 2803
    
    . set obs 1000
    Number of observations (_N) was 0, now 1,000.
    
    . gen y = rnormal()
    
    . centile y, centile(2.5 97.5)
    
                                                              Binom. interp.  
        Variable |       Obs  Percentile    Centile        [95% conf. interval]
    -------------+-------------------------------------------------------------
               y |     1,000        2.5    -1.90444       -2.032183    -1.77024
                 |                 97.5    2.038576        1.889042    2.317331
    
    . return list
    
    scalars:
                 r(n_cent) =  2
                      r(N) =  1000
                   r(ub_2) =  2.317331126340183
                   r(lb_2) =  1.889041952620063
                    r(c_2) =  2.038575804233551
                   r(ub_1) =  -1.770239873276673
                   r(lb_1) =  -2.032183029418558
                    r(c_1) =  -1.90443973839283
    
    macros:
               r(centiles) : "2.5 97.5"

    The estimates can be read off as r(c_1) and r(c_2).

    Comment


    • #3
      This fixed the problem! Thank you so much for your help. I thought maybe if I asked it different it would make more sense. Thanks so much!

      Comment

      Working...
      X