Announcement

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

  • How to run a regression with dummies in STATA?

    Hello, I have the following regression:
    CSAD= alpha + (beta1)(1-Dummy)(Return) + (beta2)(Dummy)(Return) + (beta3)(1-Dummy)(Return2) + (beta4)(Dummy)(Return2) + u
    The Dummy will have a value of 1 or 0.
    Return and Return2 are explanatory variables.

    To run the regression in STATA do I have to create new variables such as:
    gen newvar = (1-Dummy)(Return)

    and then just do the same for the rest of the variables and run the regression with the newly created variables so:

    reg CSAD newvar newvar2 newvar3 newvar4

    Is this way correct? Is there any other way this could be done without creating 4 variables?
    I am relatively new to STATA so I do not know if running the regression as: reg CSAD (1-Dummy)(Return) .... will yield the same as if I will create 4 separate variables, could someone please tell me if creating 4 more variables is the way to go or is there a more efficient way. Can STATA recognise if I don't leave spaces that (1-Dummy)(Return) is an explanatory variable? Will it compute the (1-Dummy) and then multiply it by the Return?


    Thank you.

  • #2
    Adrian:
    despite I do not find your code self-explaining, my guess is that you're looking for a three-way interaction. If that were the case, the following toy-example might be helpful:
    Code:
    . set obs 100
    number of observations (_N) was 0, now 100
    
    . g CSAD=runiform()*100
    
    . g dummy=1 if CSAD<=32
    (67 missing values generated)
    
    . replace dummy=0 if dummy==.
    (67 real changes made)
    
    . g Return=runiform()*50
    
    . regress CSAD c.Return##c.Return##i.dummy
    
          Source |       SS           df       MS      Number of obs   =       100
    -------------+----------------------------------   F(5, 94)        =     34.97
           Model |   61355.985         5   12271.197   Prob > F        =    0.0000
        Residual |  32980.6546        94  350.858027   R-squared       =    0.6504
    -------------+----------------------------------   Adj R-squared   =    0.6318
           Total |  94336.6396        99  952.895349   Root MSE        =    18.731
    
    -----------------------------------------------------------------------------------------
                       CSAD |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    ------------------------+----------------------------------------------------------------
                     Return |  -.6942031   .7024607    -0.99   0.326    -2.088955    .7005492
                            |
          c.Return#c.Return |    .012578    .013526     0.93   0.355    -.0142781    .0394341
                            |
                    1.dummy |  -58.97464   11.56021    -5.10   0.000     -81.9277   -36.02158
                            |
             dummy#c.Return |
                         1  |   .4003272   1.121901     0.36   0.722    -1.827233    2.627888
                            |
    dummy#c.Return#c.Return |
                         1  |   -.004545   .0227999    -0.20   0.842    -.0498147    .0407246
                            |
                      _cons |   74.19441   7.745119     9.58   0.000     58.81629    89.57252
    -----------------------------------------------------------------------------------------
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Dear Carlo, I am not sure of whether I am looking at a three-way interaction but just to clarify my idea was that I would create new variables that are equal to what is next to each coefficient, so instead of having in the regression (1-Dummy) multiplied by Return, I will simply create a variable equal to this, call it say newvar and then use this newly created variable to make my regression.

      The code would look like: [Assuming I have the values for the variable "Dummy", "Return" and "Return^2" already defined]

      Code:
      gen newvar = (1-Dummy)*(Return)
      gen newvar2 = Dummy*Return
      gen newvar3 = Dummy *(Return^2)
      gen newvar4 = (1-Dummy)*(Return^2)
      
      regress CSAD newvar newvar2 newvar3 newvar4
      Do you think this way is suitable ?

      Comment


      • #4
        Adrian:
        the code is computationally feasible but probably inefficient: just to chck it, you may run the codes repoprted in #2 and #3 and see whether they generate the same results.
        Moreover, by creating interactions yourself (instead of using -fvvarlist- notation), you cannot exploit the capabilities of -margins- and -marginsplot- Stata commands.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment

        Working...
        X