[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Clustered Data Format |

Date |
Wed, 18 Mar 2009 14:03:59 -0000 |

Just a tweak on this excellent advice: Numbering at the end of variable names is not compulsory so far as -reshape- is concerned, just a good idea in that later analyses are likely to be easier that way. Incidentally, Stata's idea of format is indicated by considering -format-. These problems are more widely regarded as problems of data structure. Nick n.j.cox@durham.ac.uk Matt Spittal The command -reshape- is one way to tackle this problem. The trick that often catches me out is the naming of the y variable -- it needs to have a number at the end to signify the wave (e.g. y1, y2, ..., yn). Using your example: clear input patientid y_first y_second days_betw 299729 0 0 64 295861 0.17 0.08 63 292641 0.15 0.5 69 end We then rename the y variable rename y_first y1 rename y_second y2 And then use the -reshape- command reshape long y, i(patientid) j(wave) Note that you can convert a dataset from long format to wide format with -reshape wide-. Finally, I noticed that you want the variable days_betw to be set to zero if this is the first measurement. replace days_betw = 0 if wave == 1 See -help reshape- for more information on this command. On 18/3/09 11:37 AM, "john metcalfe" <johnzmetcalfe@gmail.com> wrote: > Dear Statalist, > Forgive me if this is too elementary of a question, but I have a > longitudinal data set in Format A below upon which I would like to > perform linear mixed effects regression (y on days_b grouped by > patientid). Is there an easy way to convert the data to Format B? > Many thanks, > John > > Format A: (current) > patientid y_first y_second days_betw > 299729 0 0 64 > 295861 0.17 0.08 63 > 292641 0.15 0.5 69 > > Format B: (desired) > patientid y days_betw > 299729 0 0 > 299729 0 64 > 295861 0.17 0 > 295861 0.08 63 > 292641 0.15 0 > 292641 0.5 69 * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Clustered Data Format***From:*john metcalfe <johnzmetcalfe@gmail.com>

**Re: st: Clustered Data Format***From:*Matt Spittal <Matt.Spittal@cancervic.org.au>

- Prev by Date:
**RE: st: bys and [_N] within replace** - Next by Date:
**st: New package -ifwins- "if wins!" on SSC to subset data by "if" exp first then "in" range** - Previous by thread:
**Re: st: Clustered Data Format** - Next by thread:
**st: Bar Chart Area Pattern** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |