I'm trying to reshape a large dataset from wide to long. I use Stata 16. There are two types of IDs (dementiapatient and caregiver, n=281) with variables covering two periods (0, 6), and a number of timeinvariant variables (e.g. demdiagnose, sex etc.). The name of the time-variant variables are similar across time, noted with _t, and within a topic, for example: mobid1_0 mobid2_0 mobid1_6 mobid2_6. The type of variables varies across topic and time, some are string in month 6 and numeric in month 0.
This is an excerpt of the dataset (reduced to 5 obs.):
Code:
* Example generated by -dataex-. To install: ssc install dataex dataex pwdID_0 pwd_age_0 demdiagn pwd_sex pwd_number_reg_medications_0 rud8_hnhours_pwd_0 mobid1_0 qol_pwd1_0 cg_ID_0 cg_sex rud_padl_hrs_0 qol_cg1_0 gds1_0 in 1/5 clear input float(pwdID_0 pwd_age_0) byte(demdiagn pwd_sex) float pwd_number_reg_medications_0 str5 rud8_hnhours_pwd_0 double mobid1_0 int(qol_pwd1_0 cg_ID_0) byte cg_sex double rud_padl_hrs_0 byte(qol_cg1_0 gds1_0) 1 86.20944 1 2 3 "0.25" 2 4 100 1 0 4 1 2 79.91239 2 2 10 "0.50" 2 1 101 2 . 3 1 3 84.36961 5 2 2 "2" 2 4 102 2 0 3 2 4 84.37782 5 1 1 "0" 2 3 103 1 1 2 1 5 71.126625 5 1 3 "0" 2 4 104 1 0 3 1 end label values demdiagn demdiagn label def demdiagn 1 "Alzheimers sykdom", modify label def demdiagn 2 "Vaskulær demens", modify label def demdiagn 5 "Blandet/uspesifisert demens", modify label values pwd_sex sex_pmd label def sex_pmd 1 "Female", modify label def sex_pmd 2 "Male", modify label values mobid1_0 Yes_no label def Yes_no 2 "Nei", modify label values qol_pwd1_0 QoL label def QoL 1 "Dårlig", modify label def QoL 3 "God", modify label def QoL 4 "Svært god", modify label values cg_sex Kjønn label def Kjønn 1 "Mann", modify label def Kjønn 2 "Kvinne", modify label values qol_cg1_0 Qol label def Qol 2 "Noenlunde", modify label def Qol 3 "God", modify label def Qol 4 "Svært god", modify label values gds1_0 GDS label def GDS 1 "Ja", modify label def GDS 2 "Nei", modify
Code:
unab stubs: *_0 local stubs: subinstr local stubs "_0" "", all reshape long `stubs' i(pwdID_0) j(month) string
Code:
reshape long `stubs' i(pwdID_0) j(month) string (note: j = 6_6 _0 _6 _offered_6 _time_6 al_0 al_6 e_6) Variable pwd_number_reg_medications_offered_6 implied name too long r(198);
Kind regards,
Renira Angeles
0 Response to Problems with reshape long large dataset
Post a Comment