Announcement

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

  • Longitudinal data analysis and how to graph

    Dear Statalist users,

    I am new to longitudinal data analysis and I would most appreciate your help. I have a dataset of over 400 patients who underwent surgery and serial echo examination during follow-up. The number of echo and the time of examination after surgery (in years) changes from patient to patient. I want to analyse the change over time of an echo parameter that is indeed an ordinal variable (0 to 4+). I believe that the correct method is a mixed-effect model using:

    Code:
    xtmixed y TimeOfEcho // ID:, mle
    further, how can I graph these changes over time? It seems that using the mean of Y over time is not correct. Some authors for similar analysis have estimated the proportion of patients with each degree of y over time and depicted the change in these proportions (but they used SAS). Is it possible to do the same with STATA and how please?

    I am using STATA IC 15.1

    Thank you very much in advance, any help is greatly appreciated.

  • #2
    First, a syntax issue:
    Code:
    xtmixed y TimeOfEcho // ID:, mle
    is incorrect. The // character sequence tells Stata that the rest of the line is just a comment, so the entire ID level of the model would be ignored. What you want is
    Code:
    xtmixed y TimeOfEcho || ID:, mle
    Also, since version 13, -xtmixed- was renamed to -mixed-. The older name still works, but at some future time it may go unrecognized. So best to get in the habit of calling it by its current name now. Also, in current Stata, maximum likelihood is the default estimation method for -mixed-, so the -mle- option, though harmless, is not necessary and does nothing.

    That said, if y is an ordinal variable and it is not reasonable to treat the categories 0, 1, 2, 3, and 4 as equally spaced values of a truly numerical (interval-level) variable, then using -mixed- may be inappropriate. If you would like to analyze y as a truly ordinal variable, you would be better off with
    Code:
    meologit y TimeOfEcho || ID:
    Of course, all of the above commands are about modeling the outcome as a function of TimeOfEcho, and not about graphing. If you want to graph the modeled results, first select a range of interesting values of TimeOfEcho. For purposes of illustrating the code, I will assume that the interesting values are 0, 2, 4, 6, 8, and 10--but you should substitute the values that are relevant to you.

    Code:
    meologit y TimeOfEcho || ID:
    margins, at(TimeOfEcho = (0 2 4 6 8 10))
    marginsplot
    Note: this code may not work as expected if you are using an older version of Stata. The default outputs of -margins- have changed over time. With older versions of Stata you would have to specify some additional options in the -margins- command to get the predicted probabilities of each level of y at each value of TimeOfEcho. But I don't remember the syntax for those. See -help melogit postestimation- and click on the link to -margins- for additional information.

    You can customize the appearance of the graph to your taste by specifying -graph twoway- options in your -marginsplot- command: nearly all -graph twoway- options are accepted.

    Comment


    • #3
      Thank you so much Clyde, your help has been of paramount importance for my analysis.

      I wonder also if on the curves after marginsplot I can add some of the crude estimates of grouped raw data in order to show the model fitting....

      Many Thanks again

      Stefano

      Comment


      • #4
        I have never had occasion to do this myself, but I believe you can do it by using the -addplot()- option. If you're using current Stata, you'll find details about -addplot()- on page 428 in the Options [G-3] section of the Graph volume of the PDF manuals that are installed along with your Stata. -addplot()- is an option applicable to -graph twoway-, and -marginsplot- accepts -graph twoway- options.

        Comment

        Working...
        X