Announcement

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

  • How to use margins and marginsplot after sem?

    Hello everyone, this is my first Statalist post. I am trying to use the margins command after an OLS regression model with weighted data and full information maximum likelihood (FIML). I am also including an interaction term in my model. When I tried to run the margins command, there was an error message saying " factor XXX not found in list of covariates." XXX is my main IV variable, here it is TV time (0= low, 1=medium, 2=high hours). Can anyone help me and let me know where the problem is and how to fix it?

    I am trying to find out whether the effect of tv_time on depression varies by age. In the following model, agexlow, agexmid, and agexhigh are the mannually created interaction terms between age and tv_time.

    My codes are as follows:

    xi: sem (depress <- i.tv_time age agexlow agexmid agexhigh i.gender i.race i.educ) [pw=weight], method (mlmv)
    margins tv_time, at(age=(17(10)98)) vsquish


    Thanks a lot in advance!


  • #2
    -margins- is not compatible with the use of the -xi:- prefix. And it is also not compatible with "home brew" interactions like agexlow, etc.So you need to redo your -sem- command to make it -margins- compatible. The first thing you will need to do is to get rid of the agex* variables, and replace them with proper factor variable notation:
    Code:
    gsem (depress <- i.tv_time##c.age i.gender i.race i.educ) [pw=weight], method (mlmv) // NOTE: NO xi:
    margins tv_time, at(age=(17(10)98)) vsquish
    You also need to use -gsem-, not -sem- here because -sem- does not allow interaction terms.

    Do read -help fvvarlist- for more information about factor-variable notation.

    Comment


    • #3
      Thank you so much, Clyde! It seems that -gsem- does not work with mlmv in Stata. Do you know any other ways to apply full information likelihood in this situation?

      Comment


      • #4
        Ah, yes, I forgot about that. You are right, -gsem- does not implement full-information maximum likelihood estimation. I don't know of anyway to simultaneously support estimation with FIML, interaction effects, and postestimation with -margins- in Stata. It seems you can have any two of the three, but not all three.

        Perhaps there is a way to do this that I'm unfamiliar with. If anybody else out there knows of one, please do chime in here.

        Comment

        Working...
        X