Announcement

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

  • Margins command produces same marginal effects for evaluation at different values (interaction term of continuous and categorical variable)

    Dear all,

    I am currently performing an FE estimation with an interaction term of a continuous and a categorical variable. After that, I try to evaluate the marginal effects of the categorical variable (AVEMAG) at different levels of the continuous variable (logaidpc). However, the output of the respective margins command provides a constant marginal effect for all values of the continuous vairable. This constant effect is actually the coefficient on the AVEMAG variable without the interaction term in the regression. I am sure I overlooked some small mistake and would be grateful for any help!

    Many thanks in advance,
    Sarah

    xtreg logflows logaidpc logaffectedaidpc logtotalaffected logavemagaidpc AVEMAG $logcontrols i.year, fe cluster(numcode)

    margins, dydx(AVEMAG) at(logaidpc=(0, 1.2, 1.3, 2, 5))

    Average marginal effects Number of obs = 1495
    Model VCE : Robust

    Expression : Linear prediction, predict()
    dy/dx w.r.t. : AVEMAG

    1._at : logaidpc = 0

    2._at : logaidpc = 1.2

    3._at : logaidpc = 1.3

    4._at : logaidpc = 2

    5._at : logaidpc = 5

    ------------------------------------------------------------------------------
    | Delta-method
    | dy/dx Std. Err. z P>|z| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    AVEMAG |
    _at |
    1 | 1.338825 .4765575 2.81 0.005 .4047899 2.272861
    2 | 1.338825 .4765575 2.81 0.005 .4047899 2.272861
    3 | 1.338825 .4765575 2.81 0.005 .4047899 2.272861
    4 | 1.338825 .4765575 2.81 0.005 .4047899 2.272861
    5 | 1.338825 .4765575 2.81 0.005 .4047899 2.272861
    ------------------------------------------------------------------------------

  • #2
    Well, the problem is that you didn't use factor variable notation in the regression command, so -margins- does not understand your model correctly.

    Taking your model at "face value" without knowing how you created these variables, there is no interaction term anywhere in your model. I imagine that you think of logavemagaidpc as an interaction term, and you probably created it as -gen logavemagaidpc = logaidpc*AVEMAG-, but Stata does not "remember" the history of how this variable was created, so -margins- "thinks" logavemagaidpc is just another variable in the model, and doesn't know it's an interaction. You need to re-do your regression using factor variable notation.

    Code:
    xtreg logflows logaffectedaidpc logtotalaffected c.logaidpc##i.AVEMAG $logcontrols i.year, fe cluster(numcode)
    
    margins, dydx(AVEMAG) at(logaidpc = (0 1.2 1.3 2 5))
    Factor variable notation is one of Stata's most useful features. Do read -help fvvarlist- and then follow-up with the section in the manuals. The effort will be amply repaid.

    As an aside, using global macros when a local macro would serve is not safe. If there is any program in memory that also uses a global macro called $logcontrols, then it will overwrite yours or yours will overwrite its. The resulting bugs can be maddeningly difficult to find and fix. If your reason for using a global macro here is that you wish to use this same list of covariates in multiple analyses scattered over several different do-files, the safer way to proceed is to create a separate do-file containing a single command that defines a local macro with that list of variables, and then -include- it in each of the analytic do files. (See -help include-, a little known but very useful command.) You can then assure yourself that the same local macro definition applies to all of your analyses, yet you have the safety of using a local macro that cannot be clobbered by code that you do not control (or even, necessarily, have any awareness of.)

    Finally, to assure maximum readability of results that you post, please copy them from the Results window or your log file into a code block in the Forum editor. If you are not familiar with setting up code blocks (like the one I show above), you can find the instructions in FAQ #12.

    Comment


    • #3
      Dear Mr. Schechter,

      thank you very much for the useful help in a very understandable and fast way of provision!
      Yes, you were right and I see the point.

      I will be glad to take your comments on the readability of my posts into account.

      Have a nice evening,
      Sarah

      Comment

      Working...
      X