Hello everyone. Thanks for looking at my post. I hope you can help a PhD candidate...
I have a data set with 170 subjects, each of whom have daily repeated measures for up to 7 days, in addition to many one-time measures like demographics, baseline characteristics, and outcomes. My data is in long form and each subject has a different number of rows. In long shape it is 1800 rows and there are about 100 columns. I need to convert the whole thing to wide format to work on a mixed effects logistic regression model. I didn't have a good "j" variable for the "reshape wide" command. I tried creating one which I called j1 with [by record_id: generate j1 = _n] which appears to give me a unique variable within each subject, but when I tried [reshape wide age race ethnicity ... [ 100 variables], i(record_id) j(j1)]. I got the command to run and my data is reshaped to (really)wide, but those measures which should only occur once (e.g., age, BMI, mortality) now are duplicated 19 times (i.e., age1, age2, ..., age19). when I tried to reshape with only the daily repeating measures, the command won't run and I get "variable variablename not constant within record_id." I could go through air drop almost 2,000 useless variables, but is there a more eloquent way?
I'm using Stata/IC 14.2 running in a Microsoft remote desktop on a mac. I hope this post was both precise enough and concise enough.
Thank You,
Tom Lawson
Related Posts with converting long to wide - creating a j variable
Weighting data with AIPW and teffectsHello everyone, Actually, I try to understand how to use an IPW estimator. I have 11 treatments var…
if & else if syntaxDear Stata users, I wrote a very simple program to caculate efficacy coefficient. The program is as…
Independent variables change signs when interaction is includedHey stata experts, I am currently writing my master thesis, therefore using stata. I have a question…
Unexpected error from XTPMG outputHi dear all. I am having an unexpected error message from xtpmg output. I am using Stata 16 for Mac…
calculating or identifying start/stop dates according to a rule with consecutive observationsHi, this is a snap shot of my data set. Code: Code: * Example generated by -dataex-. To install:…
Subscribe to:
Post Comments (Atom)
0 Response to converting long to wide - creating a j variable
Post a Comment