Announcement

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

  • Binary regression and dummies variables

    Hi everyone,

    I want to estimate the coefficient of the following regression : y = Alpha0 + Theta* dt + Alpha1 * xt * (1-dt) + Alpha 2 * xt * dt + ut
    with dt = dummy variable.

    I have implemented the code attached on Stata:
    However, as you can see, there is a main effect for xt in stata and I want to remove it, in order to have the regression above in BOLD (without main effect for xt).
    Because I get from stata, the following regression : yt = Alpha0 + Theta * dt + Alpha1 * xt + Alpha 2 * xt * (1-dt) + Alpha 3* xt * dt + ut when I have run the
    command: reg y x d c.x#d

    Could you explain to me how I can write the right regression in BOLD on stata ?

    Thanks in advance,

    Pita



    Attached Files

  • #2
    Your regression is

    Code:
    regress y 1.d c.x#0.d c.x#1.d

    Some of the variables will be dropped due to collinearity. You can not include both levels of the 0/1 indicator in the regression at the same time.

    Comment


    • #3
      Thanks, Andrew for your answer.

      I get the following result attached:

      But I don't understand, why you said that I cannot include both levels of the 0/1 indicator in the regression at the same time. Do you mean in my previous regression code ? this one: reg y x d c.x#d
      I didn't get a message from stata telling me that there were omitted variables.

      Also I want to use egranger with the correct regression but I receive the following message: 1: operator invalid r(198);





      Attached Files

      Comment


      • #4
        I didn't get a message from stata telling me that there were omitted variables.
        You are correct, as we excluded the variable "x" from the regression, there is no collinearity.


        Also I want to use egranger with the correct regression but I receive the following message: 1: operator invalid r(198);
        I don't use the command, but it is probably having a problem with the factor variable notation. Generate the variables yourself and see if it solves it.

        Code:
        gen int1= c.x#0.d
        gen int2=c.x#1.d
        regress y d int1 int2

        Comment


        • #5
          Thanks a lot, Andrew. You Rock

          It works (see attached document). I can use the egranger command now.

          If I may ask you, two other questions:

          1) Is it correct and usual to have a regression with a dummy variable and without the main effect for x ?
          2) It the correct code and regression you gave:

          • c.x#0.d = int1 is equivalent to:Alpha1 * xt * (1-dt) ? and * c.x#1.d = int2 is equivalent to:Alpha 2 * xt * dt ? And for the coefficients, will stata interpret them as the impact of x on y when it is a female (int1) and when it is a male in the second case (int2) if dt = 1 if female ? ​​​​Thanks in Advance.
          Attached Files

          Comment


          • #6
            1) Is it correct and usual to have a regression with a dummy variable and without the main effect for x ?
            If you have a continuous variable and indicator and want to interact them, all that your specification does is to relabel the coefficient on the excluded continuous variable. The gist of this is summarized by my comment in #2

            You can not include both levels of the 0/1 indicator in the regression at the same time.
            Notice below that the coefficient on one of the interactions is exactly the coefficient on the excluded continuous variable in a properly interacted model. So, no there is no problem with your specification as it is exactly the same model as the properly interacted model. However, leaving out main effects and not specifying the full set of interactions will in general lead to a misspecified model.

            Code:
            sysuse auto, clear
            regress price 1.foreign 0.foreign#c.mpg 1.foreign#c.mpg
            regress price i.foreign##c.mpg
            Res.:

            Code:
            . regress price 1.foreign 0.foreign#c.mpg 1.foreign#c.mpg
            
                  Source |       SS           df       MS      Number of obs   =        74
            -------------+----------------------------------   F(3, 70)        =      9.48
                   Model |   183435281         3  61145093.6   Prob > F        =    0.0000
                Residual |   451630115        70  6451858.79   R-squared       =    0.2888
            -------------+----------------------------------   Adj R-squared   =    0.2584
                   Total |   635065396        73  8699525.97   Root MSE        =    2540.1
            
            -------------------------------------------------------------------------------
                    price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            --------------+----------------------------------------------------------------
                  foreign |
                 Foreign  |  -13.58741   2634.664    -0.01   0.996    -5268.258    5241.084
                          |
            foreign#c.mpg |
                Domestic  |  -329.2551   74.98545    -4.39   0.000    -478.8088   -179.7013
                 Foreign  |  -250.3668    83.8404    -2.99   0.004    -417.5812    -83.1524
                          |
                    _cons |   12600.54   1527.888     8.25   0.000     9553.261    15647.81
            -------------------------------------------------------------------------------
            
            .
            . regress price i.foreign##c.mpg
            
                  Source |       SS           df       MS      Number of obs   =        74
            -------------+----------------------------------   F(3, 70)        =      9.48
                   Model |   183435281         3  61145093.6   Prob > F        =    0.0000
                Residual |   451630115        70  6451858.79   R-squared       =    0.2888
            -------------+----------------------------------   Adj R-squared   =    0.2584
                   Total |   635065396        73  8699525.97   Root MSE        =    2540.1
            
            -------------------------------------------------------------------------------
                    price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            --------------+----------------------------------------------------------------
                  foreign |
                 Foreign  |  -13.58741   2634.664    -0.01   0.996    -5268.258    5241.084
                      mpg |  -329.2551   74.98545    -4.39   0.000    -478.8088   -179.7013
                          |
            foreign#c.mpg |
                 Foreign  |   78.88826   112.4812     0.70   0.485    -145.4485     303.225
                          |
                    _cons |   12600.54   1527.888     8.25   0.000     9553.261    15647.81
            -------------------------------------------------------------------------------
            
            .
            Also, the coefficient on foreign#c.mpg in the second regression is the difference between the interaction coefficients in the first regression, i.e., 78.89= -250.37 - (-329.26).
            Last edited by Andrew Musau; 21 Nov 2021, 06:33.

            Comment


            • #7
              Oh right, thank you very much for your explanations and for the example. I understand much better now.

              But does it still mean in my example that :
              The code : regress y 1.d c.x#0.d c.x#1.d is equivalent to y = Alpha0 + Theta* dt + Alpha1 * xt * (1-dt) + Alpha 2 * xt * dt + ut ? As you can see the main effect is not present for x in the regression above in bold and italics.

              Comment


              • #8
                But does it still mean in my example that :
                The code : regress y 1.d c.x#0.d c.x#1.d is equivalent to y = Alpha0 + Theta* dt + Alpha1 * xt * (1-dt) + Alpha 2 * xt * dt + ut ?
                Correct.

                Comment


                • #9
                  Thank you very much Andrew for your help.

                  This is a question that has nothing to do with the post, but do you know, how on Stata I can perform a rollling window granger causality or a time varying granger causality? I searched for a long time on internet and forums and I didn't find anything except an add in named roll a added in Eviews. I also found the asreg command (state) but I don't think it applies to a granger causality.

                  Asreg : https://www.statalist.org/forums/for...-rolling-betas

                  Thanks in advance if you know the answer.

                  Comment


                  • #10
                    Start a new thread and be more explicit in terms of how you define your windows.

                    Comment


                    • #11
                      Ok thank you

                      Comment

                      Working...
                      X