Announcement

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

  • MI & GSEM

    Morning,

    I am looking to run a path analysis (two variables measured at two time points) using gsem. I also want to control for clustering by school. I have run the following code:

    mi estimate, cmdok: gsem (grm_dst3 <- grm_dst1 [school_id]) (grm_disst3 <- grm_disst1 [school_id]) (grm_disst3 <- grm_dst1 [school_id]) ('grm_dst3' <- 'grm_disst1' [school_id]), ///
    cov(M1[school_id]*M2[school_id]@0)

    However, I am getting an error message:

    ' invalid name
    an error occurred when mi estimate executed gsem on m=1


    I am fairly new to STATA so I apologise if I am missing something obvious here.

    Any guidance would be appreciated. Thanks!


  • #2
    The part that's triggering the error is
    Code:
    ('grm_dst3' <- 'grm_disst1' [school_id])
    There should not be quotation marks around grm_dst3 and grm_disst1.

    Added: If your intention in that equation is not to refer to the variables grm_dst3 and grm_disst1 that you have used elsewhere in the -gsem- command but to some other variables whose names are stored in local macros named (confusingly to humans, though Stata doesn't mind) grm_dst3 and grm_disst1, then you have used the wrong character for the opening quote. To dereference a local macro you surround it by ` and '. The first of these is the grave accent which, on a US keyboard, is the lower case character on the key immediately to the left of the 1! key.
    Last edited by Clyde Schechter; 19 Sep 2021, 20:11.

    Comment


    • #3
      Thanks for your help!

      Missing those quotation marks was poor on my behalf. Apologies. I ran the code after removing the quotation marks and got the same error


      mi estimate, cmdok: gsem (grm_dst3 <- grm_dst1 [school_id]) (grm_disst3 <- grm_disst1 [school_id]) (grm_disst3 <- grm_dst1 [school_id]) (grm_dst3 <- grm_disst1 [school_id]), ///
      cov(M1[school_id]*M2[school_id]@0)

      ERROR
      weights not allowed
      an error occurred when mi estimate executed gsem on m=1

      The grm_dst3 and grm_disst1 variables are the same as used earlier in the command. Does this mean I keep the opening quote as is?

      Comment


      • #4
        No, you are not getting the same error message--you are getting a different error message. Do not keep the quote. There should be no quotes in your command.

        The problem now is that Stata thinks you are trying to use school_id as a weighting variable, where as you are trying to use it as the grouping variable for random slopes. You have the syntax for random slopes wrong--sorry I didn't notice this earlier. I can't give you complete corrections for this because you have not indicated whether your grm_* variables are discrete or continuous. I'm going to guess they are continuous because they appear as outcome variables in your -gsem- command with the default linear regression. So something like this:

        Code:
        mi estimate, cmdok: gsem (grm_dst3 <-grm_dst1 c.grm_dst1#M1[school_id] M2[school_id]) ///
            (grm_disst3 <-grm_disst1 c.grm_disst1#M3[school_id] M4[school_id]) ///
            (grm_disst3 <-grm_dst1 c.grm_dst1#M5[school_id] M6[school_id]) ///
            (grm_dst_3 <-grm_disst1 c.grm_disst1#M7[school_id] M8[school_id])
        Notes:
        1. This code is untested.
        2. It may contain typos I have not noticed. I also offer no opinion on whether this model is identifiable.
        3. I have not specified any -cov()- options because it appears you want to set them to zero anyway. Since 0 covariance is the default when nothing is specified, it is cleaner code to omit them.

        I also recommend that before you run this under multiple imputation, you first run and debug your -gsem- model on the unimputed original data set first. When you have -gsem- working on its own, then do it under MI. -mi estimate- and -gsem- are, in my experience, both tricky commands to work with. Dealing with the complications of one at a time will make life simpler.

        Comment


        • #5
          Thank you for this. Yes, the grm_* variables are all continuous.

          I appreciate the suggestion. I've been trying to get the gsem to run without error. I tried with the following code (ignoring MI for now). However, it is failing to converge (error message: convergence not achieved). Is there a way to address this?

          gsem (ds_t3 <- c.Grm_dst1 c.Grm_disst1 M1[school_id])(diss_t3 <- c.Grm_disst1 c.Grm_dst1 M2[school_id])


          Comment


          • #6
            Some generic suggestions for dealing with convergence problems are at https://www3.nd.edu/~rwilliam/stats3/L02.pdf
            -------------------------------------------
            Richard Williams, Notre Dame Dept of Sociology
            StataNow Version: 19.5 MP (2 processor)

            EMAIL: [email protected]
            WWW: https://www3.nd.edu/~rwilliam

            Comment


            • #7
              Thank you. Appreciate this doc.

              Comment

              Working...
              X