Announcement

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

  • Random slopes for categorical variable (3 groups)

    Dear Stata experts,

    I'm trying to fit a random slope model for longitudinal dataset. My dependent variable is continous variable and my independent variable was continous but I've converted into tertiles. I need a random slope for each tertile. Also, I've a time variable to adjust for which is continous as well. When I prefix R for the Y variable in random slope part, it doesn't run appropriately. Can you pleaes guide on how to get a slope for each tertiles? Also, I need to add in interaction between time and Y varible (tertile).

    Thank you!

    Here's my code: [mixed X i.Y time || ptid: R.Y]

  • #2
    If you are running the current version of Stata (and, if not, you are supposed to say so) or version then you can run - mixed X i.Y time || ptid: i.Y-. If you are running an older version, then this syntax is not available to you. In that case, you need to create indicator variables for the tertiles and use those instead. Something like:
    Code:
    mixed X tertile1 tertile2 tertile3 time || ptid: tertile1 tertile2 tertile3
    Note: Because the three tertile variables, Stata will omit one of them from estimation. This is not a problem, so don't worry about it.

    The main drawback is that you now cannot use -margins- to further analyze these results.

    Comment


    • #3
      As a complete aside, anjana you may want to give these articles a read, concerning converting a continuous variable into categorical:

      https://pubmed.ncbi.nlm.nih.gov/16217841/

      http://www.stat.columbia.edu/~gelman...ed/thirds5.pdf

      Comment


      • #4
        Thank you Clyde. I was working on Stata 15 until now. Fortunately, I now have access to Stata 17 for sometime.

        Comment


        • #5
          Hi Clyde, I tried using R. for factor variable in Stata 17, it was not different than Stata 15. I need slopes for all the 3 tertiles to compare the how each group is performing. Please guide how can we get slopes for each group in tertiles. Thank you so much! Kind regards, Anjana

          Comment


          • #6
            Since your independent variable is now discrete, with 3 levels, you cannot really speak of "slope" in association with it. Rather, the regression output will give you an increment in the outcome variable associated with tertile 2 compared to tertile 1 and tertile 3 compared to tertile 1. You can make those effects random at the id level using the code showed in #2. But that doesn't change anything: you don't get three slopes. You don't really get any slopes. You get two increments above the base tertile 1. If you want slopes, go back to the continuous variable, which as pointed out in #3 is probably a better analysis anyway.

            Comment

            Working...
            X