Announcement

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

  • Two-way graph of longitudinal data

    I have the following data below with pre-treatment data (denoted with the negative times) and post-treatment data (denoted with the positive times). I would like to graph this two-way to create a %predicted value of MT which are already percent values. I am trying to graph it similar to figure 2 in this publication (https://pubmed.ncbi.nlm.nih.gov/27816444/). However, I get a straight line in my graph when I use the codes below.


    Click image for larger version

Name:	example.tif
Views:	1
Size:	7.2 KB
ID:	1556783


    Code:
    mixed MT c.time || id:, covariance(unstructured) nolrtest nolog
    quietly margins , at(time = (-5(1)5))
    marginsplot , title("") plotopts(msymbol(none) lcolor(black)) ytitle(BP (%)) ylabel( , angle(horizontal) nogrid) xtitle(months) level(50) recastci(rline) ciopts(lcolor(black) lpattern(dash)) xline(0)
    end

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(id time) int MT
     1  -5 110
     1  -2 116
     1   1 189
     2  -3 135
     2  -1 170
     2   1 106
     2   2 155
     8  -4 149
     8  -1 169
     8   1 160
    11 -10 170
    11  -1 180
    11   1 144
    14  -5 174
    14  -1 149
    14   1 145
    14   2 133
    14   5 100
    end

  • #2
    Your model assumes that there is a straight line. Margins and marginsplot just summarize the model, so it should also result in a straight line. The solution is to change the model to allow for non-linearity, See e.g. this Stata tip: http://maartenbuis.nl/publications/leaps.html
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Hi Maarten, Thank you. This is exactly what I needed. I can use this with my mixed methods regression model. My only question is how I can structure the data to conduct this analysis. For the nlsw88 data use in your example, the data only has one observation per id. In my dataset, participants have multiple time and MT data depending on the pre-intervention enrollment and post-intervention measures. Do I have to reshape the data to be wide for those variables and if I do, how I do I add the time-varying variables since they will now be separated. I started using the code below but the I realized I may have it wrong since I have multiple entries.


      Code:
      gen aft=time>0
      mixed MT c.time##c.aft || id:, covariance(unstructured) nolrtest nolog
      lincom c.time#c.aft + aft
      quietly margins, at(race=1 graft=1 smoke=2), over(time)
      marginsplot , title("") plotopts(msymbol(none) lcolor(black)) ytitle(MT (%)) ylabel( , angle(horizontal) nogrid) xtitle(months) level(50) recastci(rline) ciopts(lcolor(black) lpattern(dash)) xline(0)

      Comment

      Working...
      X