Announcement

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

  • New to margins command - verifying correct use to calculate partial effects

    I’m running Stata 14 on Windows 11. I’m running a fixed-effects regression on a panel dataset, where each observation is a country-year. For each country, within a set of years (the years are not necessarily the same for each country), I’d like to calculate the partial effect of (log of) GDP on (log of) various outcome variables (e.g. employment).

    I’d like to verify that my setup is correct for this desired result. I get results from my code and they seem reasonable, but this is the first time I’ve used the margins command, so would like to make sure I’m interpreting it correctly.

    I’ve set this up as follows:
    Code:
    reg y i.country i.country#c.log_gdp log_otherxvars, vce(robust)
    margins i.country, dydx(log_gdp)
    Is this correct for the desired result?

    Thanks,
    Robert

  • #2
    The regression is wrong. If you are going to use the # operator for interactions, then you must also include both of the constituents of the interaction separately. So you need to add c.log_gdp to the right hand side. Alternatively, I find it simpler not to use the # operator. I use the ## operator, so then I just have to write the interaction as i.country##c.log_gdp. Then you don't need to separately write i.country, nor c.log_gdp.

    As for the margins command, once you fix the regression, it is correct for the country-specific effects of log_gdp on y, but not on log y. To get the effects on log y, change -dydx- to -eydx-.

    Comment


    • #3
      Perfect, thanks. Good point about including both of the constituents of the interaction; I absolutely should be doing that.

      That said: here I am running
      Code:
       reg y i.country##c.log_gdp, vce(robust)
      and when I run the margins command, I get a warning message: variance matrix is nonsymmetric or highly singular. (The margins command produces coefficient estimates, but not SE's, t-stats, or CI's.)

      When I run
      Code:
       reg y i.country#c.log_gdp log_gdp i.country, vce(robust)
      then run the same margins command, I do not get the error. That said, the point estimates of coefficients are the same ones I get when running the regression with the ## operator.

      Any ideas why this might be occurring?

      Comment


      • #4
        I really have no idea why that would happen. The two regression commands and -margins- response to it should, as far as I know, be the same.

        Comment

        Working...
        X