Announcement

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

  • How to save 1 specific xtreg beta coefficient to use in postestimations?

    Dear Stata Community members,

    I would like to ask how I can save one particular beta coefficient after running an xtreg with fixed effects (I need to save the coefficient, its standard error, P|z|, and 95% CI interval). Please note that my model has many variables but I only need to save one of the betas (the coefficient, its standard error, P|z|, and 95% CI interval).

    My objective is to use that coefficient in different postestimations (done using nlcom) after running other xtreg’s in the meantime (my post-estimation involves using coefficients from different xtregs (1 from each xtreg).

    I would also like to ask how I can extract that saved coefficient and “refer to it” in my postestimations (so that STATA understands which coefficient I am referring to). Is there any command similar to “global” which does such deed? I’ve tried several options. One member of our community kindly suggested the use of regress and suest: such command does achieve the goal but I have too many fixed effects (1500+ units, each of which having between 2-16 observations), which makes each post-estimation (nlcom) take about 1.5 hours. I need to do many estimations at this stage so this solution is not very efficient.

    I’m struggling a lot with this so your vice would be much appreciated 😊

    Kind regards,
    Joao

  • #2
    Perhaps this example will start you in a useful direction. Note that I am running Stata 16.1, if you have an earlier version some of the matrix commands may need to change in ways that I no longer remember.
    Code:
    webuse nlswork
    xtset idcode
    xtreg ln_wage age not_smsa south, fe
    matrix list r(table)
    scalar b = r(table)["b","age"]
    scalar se = r(table)["se","age"]
    display "coeficient estimate is " b " with standard error " se
    Code:
    . webuse nlswork
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . xtset idcode
           panel variable:  idcode (unbalanced)
    
    . xtreg ln_wage age not_smsa south, fe
    
    Fixed-effects (within) regression               Number of obs     =     28,502
    Group variable: idcode                          Number of groups  =      4,710
    
    R-sq:                                           Obs per group:
         within  = 0.1084                                         min =          1
         between = 0.1664                                         avg =        6.1
         overall = 0.1395                                         max =         15
    
                                                    F(3,23789)        =     964.43
    corr(u_i, Xb)  = 0.1246                         Prob > F          =     0.0000
    
    ------------------------------------------------------------------------------
         ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |   .0182881   .0003469    52.72   0.000     .0176082    .0189679
        not_smsa |  -.1016459   .0098022   -10.37   0.000    -.1208588    -.082433
           south |  -.0683062   .0112649    -6.06   0.000    -.0903861   -.0462262
           _cons |   1.200435   .0113276   105.97   0.000     1.178232    1.222638
    -------------+----------------------------------------------------------------
         sigma_u |  .39222024
         sigma_e |  .30254719
             rho |  .62695426   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    F test that all u_i=0: F(4709, 23789) = 7.73                 Prob > F = 0.0000
    
    . matrix list r(table)
    
    r(table)[9,4]
                   age    not_smsa       south       _cons
         b   .01828805  -.10164593  -.06830616    1.200435
        se   .00034687   .00980219   .01126493    .0113276
         t   52.723746  -10.369713  -6.0636131   105.97435
    pvalue           0   3.853e-25   1.351e-09           0
        ll   .01760818  -.12085885  -.09038613   1.1782322
        ul   .01896793    -.082433  -.04622618   1.2226378
        df       23789       23789       23789       23789
      crit   1.9600637   1.9600637   1.9600637   1.9600637
     eform           0           0           0           0
    
    . scalar b = r(table)["b","age"]
    
    . scalar se = r(table)["se","age"]
    
    . display "coeficient estimate is " b " with standard error " se
    coeficient estimate is .01828805 with standard error .00034687

    Comment

    Working...
    X