Announcement

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

  • How to save regression coefficients and SEs and event plot?

    Hi Statalisters,

    I need to save the regression coefficients and SEs of the following regression and normalize the coefficients such that all coefficients are subtracted from the coefficient of the term hurr_f1_2. It would be extremely helpf if someone can suggest a code that can save the estimates and then modify them to be plotted on a graph.


    reghdfe LProp_p $leads1 Damage $lags1 [aweight=Tot_Pop], absorb(i.fips i.state_id#i.year i.year#i.Coastal_County i.year#c.Proportion_Black i.year#c.UR i.year#c.Land_Area i.year#c.Coast_Dist i.year#c.PVR ) vce(cluster fips)


    HDFE Linear regression Number of obs = 22,987
    Absorbing 8 HDFE groups F( 11, 1102) = 2.83
    Statistics robust to heteroskedasticity Prob > F = 0.0012
    R-squared = 0.9184
    Adj R-squared = 0.9120
    Within R-sq. = 0.0050
    Number of clusters (fips) = 1,103 Root MSE = 0.2767

    (Std. err. adjusted for 1,103 clusters in fips)

    Robust
    LVio_p Coefficient std. err. t P>t [95% conf. interval]

    hurr_f9_10 .0017262 .0461595 0.04 0.970 -.0888442 .0922965
    hurr_f7_8 .0313713 .0411142 0.76 0.446 -.0492997 .1120424
    hurr_f5_6 .0290832 .0289531 1.00 0.315 -.0277263 .0858927
    hurr_f3_4 .0227471 .0341041 0.67 0.505 -.0441693 .0896635
    hurr_f1_2 .0353357 .0270934 1.30 0.192 -.0178247 .0884962
    Damage .3924539 .0990926 3.96 0.000 .1980224 .5868854
    hurr_1_2 .4602122 .1144715 4.02 0.000 .2356056 .6848189
    hurr_3_4 .5357033 .2213863 2.42 0.016 .101317 .9700896
    hurr_5_6 .2240365 .0764239 2.93 0.003 .0740837 .3739894
    hurr_7_8 .1580742 .0850028 1.86 0.063 -.0087113 .3248597
    hurr_9_10 .0384899 .0583739 0.66 0.510 -.0760465 .1530264
    _cons 3.583663 .00562 637.66 0.000 3.572636 3.59469



    * Load data and setup matrix
    matrix b = e(b)
    matrix v = e(V)

    * Normalize coefficients relative to hurr_f1_2
    scalar hurr_f1_2_coef = _b[hurr_f1_2]

    foreach var in hurr_f9_10 hurr_f7_8 hurr_f5_6 hurr_f3_4 hurr_f1_2 Damage hurr_1_2 hurr_3_4 hurr_5_6 hurr_7_8 hurr_9_10 {
    scalar `var'_norm = _b[`var'] - hurr_f1_2_coef
    scalar low_`var'_norm = `var'_norm - invttail(e(df_r),0.025)*_se[`var']
    scalar high_`var'_norm = `var'_norm + invttail(e(df_r),0.025)*_se[`var']

    di "`var'_norm' adjusted coefficient: " `var'_norm
    di "Lower 95% CI for `var'_norm': " low_`var'_norm
    di "Upper 95% CI for `var'_norm': " high_`var'_norm
    }
    Last edited by Anupam Ghosh; 23 Jan 2025, 15:35.

  • #2
    Maybe:

    Code:
    search transform_margins //install it
    clear
    sysuse auto, clear
    reghdfe mpg weight length headroom trunk , absorb(rep78) cluster(rep78)
    local coef = _b[weight]
    margins, dydx(*) 
    transform_margins @ - `coef'
    marginsplot

    Comment


    • #3
      Hi George,

      This is not working with my event plot code. Is there any other way by which I can save the coefficient and standard error estimates and build the point estimates and the CIs by hand and the

      Comment


      • #4
        r(table) gives you everything. Since the adjustment is additive,you can just shift the beta, ll, ul statistics from that table by the adjusting coefficient. The width of the CI is unchanged.

        matrix R = r(table)'

        will rotate the matrix to columns which you can svmat and then graph (maybe you can graph from the matrix).

        Comment


        • #5
          The user command regsave (ssc install regsave, replace) will save coefficients, standard errors, and more into a dataset for you.

          Code:
          sysuse auto, clear
          reghdfe price mpg displacement, absorb(foreign)
          regsave
          list
          
               +----------------------------------------------------+
               |          var       coef     stderr    N         r2 |
               |----------------------------------------------------|
            1. |          mpg   -98.8856   63.17063   74   .4631095 |
            2. | displacement   22.40416   4.634239   74   .4631095 |
            3. |        _cons   3850.973   2070.066   74   .4631095 |
               +----------------------------------------------------+
          Associate Professor of Finance and Economics
          University of Illinois
          www.julianreif.com

          Comment


          • #6
            Code:
            clear all
            
            sysuse auto, clear
            reghdfe mpg weight length trunk , absorb(rep78)
            matrix R = r(table)'
            mat li R
            
            frame create results
            frame change results
            svmat R , n(col)
            local bench = R[1,1]
            g beta_adj = b - `bench'
            g ll_adj = ll - `bench'
            g ul_adj = ul - `bench'
            g var = ""
            local var "weight length trunk _cons"
            forv i = 1/4 {
                local z = "`: word `i' of `var''"
                replace var = "`z'" in `i'
            }
            
            *frame change default

            Comment

            Working...
            X