Announcement

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

  • Regression with dummy variables and save coefficients for another regression

    Hi everyone,

    Let me first say I am a Stata - beginner. I have no experiences in using Stata. I thought I would never use Stata, however, now I have to complete my thesis as scientific research. It would appreciate it if you do me a favor.

    I have to run a model containing a dummy variable to save coefficient. The model:

    A = Beta0 + Beta1 * B + Beta2 * Decrease * B
    Decrease is a dummy variable, =1 if B<0, =0 if B>0

    I want to save coefficient Beta2 as a variable for another model. Please help me to give the full codes.

    Thank you very much for your help.

  • #2
    You refer to coefficients as follows:

    Code:
    . sysuse auto
    (1978 Automobile Data)
    
    . reg price mpg foreign, noheader
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |  -294.1955   55.69172    -5.28   0.000    -405.2417   -183.1494
         foreign |   1767.292    700.158     2.52   0.014     371.2169    3163.368
           _cons |   11905.42   1158.634    10.28   0.000     9595.164    14215.67
    ------------------------------------------------------------------------------
    
    . dis _b[foreign]
    1767.2922
    It is best to save the coefficient as a local or a scalar:

    Code:
    . sca Bforeign = _b[foreign]
    
    . dis Bforeign
    1767.2922

    Comment


    • #3
      To expand on Joro's example in #2, you could add another -regress- command with the coeflegend option (after the first -regress- command):

      Code:
      . regress, coeflegend noheader
      ------------------------------------------------------------------------------
             price |      Coef.  Legend
      -------------+----------------------------------------------------------------
               mpg |   -294.196  _b[mpg]
           foreign |   1767.292  _b[foreign]
             _cons |  11905.415  _b[_cons]
      ------------------------------------------------------------------------------

      The output shows you how to refer to all of the coefficients in the model.

      Speaking of the model, you described it as follows:

      Code:
      A = Beta0 + Beta1 * B + Beta2 * Decrease * B
      Why have you excluded the first order term for Decrease? Normally, it would be included, like this:

      Code:
      A = Beta0 + Beta1*B + Beta2*Decrease + Beta3*Decrease*B
      HTH.
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 18.5 (Windows)

      Comment


      • #4
        I am sorry but I mean my sample includes 4384 observations, so I want to have 4384 beta2.

        Comment


        • #5
          Vinh:
          in order to have 4384 beta2 you need to run 4384 different regressions with the same regressand and regressors on 4384 random samples drawn from the same population from which your original sample comes from.
          Another option may be -bootstrap-ping the coefficients you're interested in:
          Code:
          . use "C:\Program Files\Stata16\ado\base\a\auto.dta"
          (1978 Automobile Data)
          
          . regress price mpg
          
                Source |       SS           df       MS      Number of obs   =        74
          -------------+----------------------------------   F(1, 72)        =     20.26
                 Model |   139449474         1   139449474   Prob > F        =    0.0000
              Residual |   495615923        72  6883554.48   R-squared       =    0.2196
          -------------+----------------------------------   Adj R-squared   =    0.2087
                 Total |   635065396        73  8699525.97   Root MSE        =    2623.7
          
          ------------------------------------------------------------------------------
                 price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                   mpg |  -238.8943   53.07669    -4.50   0.000    -344.7008   -133.0879
                 _cons |   11253.06   1170.813     9.61   0.000     8919.088    13587.03
          ------------------------------------------------------------------------------
          
          . bootstrap _b[_cons] _b[mpg], reps(4384) saving(C:\Users\user\Desktop\regress.dta, every(1) double replace) nodots : regress price mpg
          
          Linear regression                               Number of obs     =         74
                                                          Replications      =      4,384
          
                command:  regress price mpg
                  _bs_1:  _b[_cons]
                  _bs_2:  _b[mpg]
          
          ------------------------------------------------------------------------------
                       |   Observed   Bootstrap                         Normal-based
                       |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                 _bs_1 |   11253.06   1381.144     8.15   0.000     8546.068    13960.05
                 _bs_2 |  -238.8943   58.36549    -4.09   0.000    -353.2886   -124.5001
          ------------------------------------------------------------------------------
          
          . use "C:\Users\user\Desktop\regress.dta"
          (bootstrap: regress)
          
          . list in 1/10
          
               +------------------------+
               |     _bs_1        _bs_2 |
               |------------------------|
            1. | 10387.988   -199.48343 |
            2. | 12491.573   -280.17873 |
            3. | 11027.142    -213.8032 |
            4. | 11236.428   -232.78838 |
            5. |   12603.9   -316.33807 |
               |------------------------|
            6. |  10480.61   -209.25284 |
            7. | 11522.783    -248.5052 |
            8. | 8681.1014   -135.67664 |
            9. | 12383.148   -282.87175 |
           10. | 11471.283   -228.69019 |
               +------------------------+
          
          .
          Last edited by Carlo Lazzaro; 15 Oct 2020, 02:16.
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            Firstly, thank you for your attention. I mean I am trying to run regressions by companyID and year, and save the coefficients for each firm-year model as new variables in a new column right besides the other columns. Can you help me again?

            Comment

            Working...
            X