Announcement

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

  • Regression with indicator variable 0 or 1

    Hello everyone,

    I'm new to Stata and I'm trying to run a regression of the form y = indicator*[constant + α0*x1 + β0*x2] + (1 - indicator)*[constant + α1*x1 + β1*x2]
    The indicator takes the value 0 or 1 and represents the economy being in a particular state (such as recession or expansion), and x1 and x2 are independent variables. It is a panel regression with fixed effects. I want to estimate the state-dependent α and β coefficients.
    I would like to just be able to type this equation into Stata and run that regression, but I don't believe that is possible. I tried pre-multiplying x1 and x2 by the indicator beforehand, and I get results but the process does not seem elegant and it is time-consuming, and I don't know if the results are correct. Does anyone know how I'm supposed to estimate such an equation in Stata?

    Thank you!
    Last edited by Martin Adams; 09 Mar 2017, 16:59.

  • #2
    Welcome to Statalist, and to Stata.

    I'm sympathetic to you as a new user of Stata - it's a lot to absorb. And even worse if perhaps you are under pressure to produce some output quickly. Nevertheless, I'd like to encourage you to take a step back from your immediate tasks.

    When I began using Stata in a serious way, I started, as have others here, by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. There are a lot of examples to copy and paste into Stata's do-file editor to run yourself, and better yet, to experiment with changing the options to see how the results change.

    All of these manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu. The objective in doing the reading was not so much to master Stata as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax, and know how to find out more about them in the help files and PDF manuals.

    The Stata documentation is really exemplary - there's just a lot of it. The path I followed surfaces the things you need to know to get started in a hurry and to work effectively.

    The model you describe is a straightforward model that is more usually written with the indicator variable fully interacted with both of the independent variables.

    Comment


    • #3
      Just a side note, after William's crystal-clear explanation and helpful advice.

      You may wish to to type in the Command Window:

      Code:
      . help xtreg
      There, you will find examples. Those with the option - fe - are the ones related to fixed-effects.

      If you click on the blue link on the top left corner, and I strongly recommend you do it, you will go directly to the Stata Manual.

      There, you have the PDFs William underlined. The embedded codes allow you to go to and through.
      Best regards,

      Marcos

      Comment


      • #4
        Originally posted by William Lisowski View Post
        Welcome to Statalist, and to Stata.

        I'm sympathetic to you as a new user of Stata - it's a lot to absorb. And even worse if perhaps you are under pressure to produce some output quickly. Nevertheless, I'd like to encourage you to take a step back from your immediate tasks.

        When I began using Stata in a serious way, I started, as have others here, by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. There are a lot of examples to copy and paste into Stata's do-file editor to run yourself, and better yet, to experiment with changing the options to see how the results change.

        All of these manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu. The objective in doing the reading was not so much to master Stata as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax, and know how to find out more about them in the help files and PDF manuals.

        The Stata documentation is really exemplary - there's just a lot of it. The path I followed surfaces the things you need to know to get started in a hurry and to work effectively.

        The model you describe is a straightforward model that is more usually written with the indicator variable fully interacted with both of the independent variables.
        Thank you for the response. I read the Stata manual looking for information that would clear up how to estimate the state-dependent regression, but I cannot find it. I'm still stuck trying to figure it out... Can anyone help me get on the right track?

        Comment


        • #5
          So it looks like you are trying to fit two separate linear models, each conditional on the value of indicator. That's just an interaction model. Since you have panel data, I'm guessing you want to use -xtreg, fe- (though there are plenty of other possibilities and the code would be analogous) and will illustrate with that. I'm also assuming x1 and x2 are continuous variables.

          Code:
          xtreg y = i.indicator##c.(x1 x2), fe
          Now the values of the betas you are looking for do not directly appear in the output (or, rather, some of the don't). To get those, just run:

          Code:
          margins indicator, dydx(x1 x2)
          The values of the alphas are just the _cons and indicator coefficients in the regression output.

          Comment


          • #6
            Originally posted by Clyde Schechter View Post
            So it looks like you are trying to fit two separate linear models, each conditional on the value of indicator. That's just an interaction model. Since you have panel data, I'm guessing you want to use -xtreg, fe- (though there are plenty of other possibilities and the code would be analogous) and will illustrate with that. I'm also assuming x1 and x2 are continuous variables.

            Code:
            xtreg y = i.indicator##c.(x1 x2), fe
            Now the values of the betas you are looking for do not directly appear in the output (or, rather, some of the don't). To get those, just run:

            Code:
            margins indicator, dydx(x1 x2)
            The values of the alphas are just the _cons and indicator coefficients in the regression output.
            Thank you very much! This was very helpful. It appears like I'm getting almost all the results I want now. There is another issue, however. The "margins" command works and gives me the coefficients, except for one regression. When I try to run one specific regression, I get estimation output, but the margins command gives the following error:

            Code:
            default prediction is a function of possibly stochastic quantities other than e(b)
            The regression has the state-dependent form I described, and regresses a variable at t (yt+0) on lagged values of that same variable (yt-1, yt-2 ... and lags of another variable). It basically estimates something like this:

            Code:
            xtreg yt  i.indicator##c.(L(1/4)yt L(0/4)x1,t), fe
            When I take yt+1 or yt+2 and so on as the dependent variable instead of yt+0, and keep the independent variables the same, the margins command does work. What could be the cause of this? I need the coefficients for the yt+0 regression as well.

            Comment


            • #7
              The recent Statalist topic at the link below began with a question about the same error message you encountered, and the resolution was a discussion of the inadvisability of estimating a model with a lagged independent variable using xtreg.

              http://www.statalist.org/forums/foru...cts-regression

              With regard to the error message you obtain, it seems to me, as it did in that discussion as well, that the lagged independent variable is itself stochastic (y = xB+e and e is stochastic), and that is the quantity to which the error message refers.

              Regarding the versions of the xtreg that did not yield the error message, I find it difficult to imagine from your pseudo-code exactly what command you might have given, and for that reason cannot speculation on why the command did not discover the problem. But rather than try to figure that out, I think you're best advised to turn your attention to finding a more appropriate model for estimation, if you plan on including the lagged dependent variable among your independent variables.

              Comment

              Working...
              X