Announcement

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

  • Saving coefficients from a regression and later used them as independent variable in another regression

    Hi,

    I am running this model: regress ln_inglab_hora experiencia experiencia_cua escolaridad period2 period3 i.id_region_birt_3, where i.id_region_birt_3 represent dummies for cohorts I have created. I only want to use the betas associated to such dummies in another regression but I am struggling on how to do it..

    Can anyone guide me on this?

    Thank you

  • #2
    One way could be regsave. Check it out and download it using search regsave. A tutorial can be found here: https://www.stata.com/meeting/boston...ton10_reif.pdf

    Comment


    • #3
      Code:
      matrix B = e(b)
      or,

      Code:
      estimates store e1
      and then

      Code:
      estimates restore e1
      to get the results back.

      Comment


      • #4
        Silvana:
        as an aside to other valuable advice, you may want to consider -statsby- (caveat: save a copy of the master dataset beforehand):
        Code:
        . sysuse auto.dta
        (1978 automobile data)
        
        . statsby, by(foreign): regress mpg gear turn
        (running regress on estimation sample)
        
              Command: regress mpg gear turn
                   By: foreign
        
        Statsby groups:
        .
        
        . list
        
             +--------------------------------------------+
             |  foreign   _b_gea~o     _b_turn    _b_cons |
             |--------------------------------------------|
          1. | Domestic   3.814768   -.7819742   41.52745 |
          2. |  Foreign   6.566766   -2.327916   84.17068 |
             +--------------------------------------------+
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Dear Ken, George ad Carlo
          Thank you very much


          What about obtaining fixed effects from the following regression and store them in a b vector as if they were the estimated parameters of a regrssion?

          xtset id_region_birt_3 period
          xtreg ln_inglab_hora experiencia experiencia_cua escolaridad ethnici1 edumo2 edumo3 edufa2 edufa3 female region_naci_Car region_naci_Ori region_naci_Cen region_naci_Pac region_naci_Otro period2 period3, fe r

          Comment


          • #6
            Silvana:
            it is the same as your first regression code with -id_region- as a predictor.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Carlo's method will do it and get you a matrix, though you may have to remove parts of it as it will include the coefficients on the Xs.

              Another way is

              Code:
              predict fe , u
              after xtreg. It creates a variable equal to the fixed effect coefficients.

              or use

              Code:
              reghdfe .... , absorb(id , savefe)
              which also creates a variable.

              This would work to create a matrix of the FE:

              Code:
              use https://www.stata-press.com/data/r18/nlswork, clear
              keep in 1/1000
              
              xtreg ln_w age  tenure , fe
              predict fe , u
              
              preserve
                   keep idcode fe
                   collapse (first) fe, by(idcode)
                   mkmat fe , matrix(FE)
              restore
              
              matrix list FE


              Comment


              • #8
                Dear George Ford,
                thank you.


                I am actually running this regression

                reghdfe ln_inglab_hora experiencia experiencia_cua escolaridad, abs(id_region_birt_3 period, savefe) vce(cluster id_region_birt_3)

                but I'm not sure how to obtain those fe that I've saved with savefe. I understand how to do it with predict when you have an output from xtreg, but I don't get it for reghdfe




                Comment


                • #9
                  Silvana:
                  the following toy-example may help:
                  Code:
                  . use https://www.stata-press.com/data/r18/nlswork.dta
                  (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
                  
                  . reghdfe ln_w grade age ttl_exp tenure not_smsa south , absorb(FE1=idcode FE2=year)
                  (dropped 550 singleton observations)
                  note: grade is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  (MWFE estimator converged in 8 iterations)
                  note: grade omitted because of collinearity
                  
                  HDFE Linear regression                            Number of obs   =     27,541
                  Absorbing 2 HDFE groups                           F(   5,  23375) =     261.99
                                                                    Prob > F        =     0.0000
                                                                    R-squared       =     0.6762
                                                                    Adj R-squared   =     0.6185
                                                                    Within R-sq.    =     0.0531
                                                                    Root MSE        =     0.2939
                  
                  ------------------------------------------------------------------------------
                       ln_wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                         grade |          0  (omitted)
                           age |   .0114497   .0099824     1.15   0.251    -.0081165    .0310159
                       ttl_exp |   .0323758   .0015046    21.52   0.000     .0294266     .035325
                        tenure |   .0104689   .0009264    11.30   0.000     .0086531    .0122847
                      not_smsa |  -.0914148   .0096386    -9.48   0.000    -.1103071   -.0725225
                         south |  -.0640471   .0110539    -5.79   0.000    -.0857134   -.0423808
                         _cons |   1.161841    .290702     4.00   0.000     .5920463    1.731636
                  ------------------------------------------------------------------------------
                  
                  Absorbed degrees of freedom:
                  -----------------------------------------------------+
                   Absorbed FE | Categories  - Redundant  = Num. Coefs |
                  -------------+---------------------------------------|
                        idcode |      4147           0        4147     |
                          year |        15           1          14     |
                  -----------------------------------------------------+
                  
                  .
                  
                  . list FE1 FE2 if idcode==1
                  
                         +------------------------+
                         |       FE1          FE2 |
                         |------------------------|
                      1. | .41666994    .10056242 |
                      2. | .41666994    .11992289 |
                      3. | .41666994    .10192435 |
                      4. | .41666994    .07946882 |
                      5. | .41666994    .04549987 |
                         |------------------------|
                      6. | .41666994    .05055576 |
                      7. | .41666994    .04673756 |
                      8. | .41666994   -.01141121 |
                      9. | .41666994   -.08817449 |
                     10. | .41666994   -.11250592 |
                         |------------------------|
                     11. | .41666994   -.17160416 |
                     12. | .41666994   -.17099379 |
                         +------------------------+
                  
                  .
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment

                  Working...
                  X