Announcement

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

  • Extracting the constant from a regression output to use it as a dependent variable

    Hi, I am relatively new to Stata. I wonder how to extract the intercept value from my regression and use it as a dependent variable in a new regression with different independent variables.

  • #2
    it's simple enough to save this (it's part of what Stata returns; see the help file); however, it has no variation and thus can't be used in the way you are thinking - but maybe your situation is that you want to estimate multiple models and save multiple intercepts and use those???? but that is just a guess and you need to clarify what you are trying to do

    Comment


    • #3
      Hello Rich, that is exactly what I am trying to do. I have a large number of funds that I have divided into 5 groups. Next, I run a regression (Carhart's 4-Factor-Model) on each of these groups and I want to save each intercept (alpha) and run another 5 regressions with the intercept coefficient as a dependent variable and using different independent variables.

      Comment


      • #4
        The regressions that I run are as follows:
        Code:
        xtset fundnr calmt
        by turnratio_5, sort : xtreg fundperf mktrf smb hml mom
        The regressions that I want to run next are:
        xtreg *saved intercept* turnratio age expratio
        Last edited by Nikifor Naumov; 11 Jul 2022, 05:26.

        Comment


        • #5
          You have misunderstood something, Nikifore. It is best if you talk to your supervisor regarding what you are supposed to do.

          Mechanically what you want to do can be done like this, but this does not make sense.

          Code:
           xtset fundnr calmt
          
           sort turnratio_5
          
           levelsof turnratio_5, local(turns)  
          
          gen fourfactoralphas = .  
          
          foreach l of local turns {
             
           xtreg fundperf mktrf smb hml mom if turnratio_5 == `l'  
          
          replace fourfactoralphas = _b[_cons]  if turnratio_5 == `l'  
          
           }
          
           xtreg fourfactoralphas turnratio age expratio
          Last edited by Joro Kolev; 11 Jul 2022, 09:10.

          Comment


          • #6
            In case I have messed up the loop, which might have happened because I do not have a data sample to work with, you can look up my post #4 at this thread here: https://www.statalist.org/forums/for...r-with-weights

            Your problem has the same structure as the problem at the cited thread.

            Comment


            • #7
              Thank you for your response, Joro. I just tried your code, but it seems to deliver only 1 regression result. My goal is to run 5 new regressions. My supervisor suggested that I save the output in scalar and then extract it from there, but I don't know how to approach it this way.
              Last edited by Nikifor Naumov; 11 Jul 2022, 10:29.

              Comment


              • #8
                My code delivers one regression per level of the variable on which we are applying -levelsof-. Here it is on a sample data. The code

                Code:
                sysuse auto, clear
                
                sort rep
                
                 levelsof rep, local(replevels)  
                
                gen alphas = .  
                
                foreach l of local replevels {
                   
                reg mpg headroom if rep == `l', noheader
                
                replace alphas = _b[_cons]  if rep == `l'  
                
                 }
                 
                 reg alphas length weight 
                 
                 tab rep alphas
                retults in

                Code:
                . sysuse auto, clear
                (1978 automobile data)
                
                . 
                . sort rep
                
                . 
                .  levelsof rep, local(replevels)  
                1 2 3 4 5
                
                . 
                . gen alphas = .  
                (74 missing values generated)
                
                . 
                . foreach l of local replevels {
                  2.    
                . reg mpg headroom if rep == `l', noheader
                  3. 
                . replace alphas = _b[_cons]  if rep == `l'  
                  4. 
                .  }
                ------------------------------------------------------------------------------
                         mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                -------------+----------------------------------------------------------------
                    headroom |         12          .        .       .            .           .
                       _cons |  -7.11e-15          .        .       .            .           .
                ------------------------------------------------------------------------------
                (2 real changes made)
                ------------------------------------------------------------------------------
                         mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                -------------+----------------------------------------------------------------
                    headroom |   -2.39759   .7939019    -3.02   0.023    -4.340198   -.4549825
                       _cons |   27.21687    2.82784     9.62   0.000     20.29739    34.13634
                ------------------------------------------------------------------------------
                (8 real changes made)
                ------------------------------------------------------------------------------
                         mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                -------------+----------------------------------------------------------------
                    headroom |  -1.566038   .9580552    -1.63   0.113    -3.528525    .3964495
                       _cons |   24.39245   3.121653     7.81   0.000     17.99804    30.78687
                ------------------------------------------------------------------------------
                (30 real changes made)
                ------------------------------------------------------------------------------
                         mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                -------------+----------------------------------------------------------------
                    headroom |  -3.364359   1.186259    -2.84   0.012    -5.879116   -.8496018
                       _cons |   31.66629   3.658968     8.65   0.000     23.90962    39.42295
                ------------------------------------------------------------------------------
                (18 real changes made)
                ------------------------------------------------------------------------------
                         mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                -------------+----------------------------------------------------------------
                    headroom |   1.052632   6.994964     0.15   0.884    -14.77108    16.87634
                       _cons |   24.68421   18.01982     1.37   0.204    -16.07946    65.44789
                ------------------------------------------------------------------------------
                (11 real changes made)
                
                .  
                .  reg alphas length weight 
                
                      Source |       SS           df       MS      Number of obs   =        69
                -------------+----------------------------------   F(2, 66)        =      0.40
                       Model |  24.5654985         2  12.2827493   Prob > F        =    0.6702
                    Residual |  2013.64609        66  30.5097892   R-squared       =    0.0121
                -------------+----------------------------------   Adj R-squared   =   -0.0179
                       Total |  2038.21159        68  29.9736998   Root MSE        =    5.5236
                
                ------------------------------------------------------------------------------
                      alphas | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                -------------+----------------------------------------------------------------
                      length |   .0661284   .0923733     0.72   0.477     -.118301    .2505577
                      weight |  -.0022553   .0026502    -0.85   0.398    -.0075467    .0030361
                       _cons |   20.34389   10.12842     2.01   0.049     .1218501    40.56592
                ------------------------------------------------------------------------------
                
                .  
                .  tab rep alphas
                
                    Repair |
                    record |                         alphas
                      1978 | -7.11e-15   24.39245   24.68421   27.21687   31.66629 |     Total
                -----------+-------------------------------------------------------+----------
                         1 |         2          0          0          0          0 |         2 
                         2 |         0          0          0          8          0 |         8 
                         3 |         0         30          0          0          0 |        30 
                         4 |         0          0          0          0         18 |        18 
                         5 |         0          0         11          0          0 |        11 
                -----------+-------------------------------------------------------+----------
                     Total |         2         30         11          8         18 |        69

                Comment

                Working...
                X