Hello!
I am working with data on women's contraceptive histories. In long form, cases are episodes of contraceptive use or non-use. In wide form, cases are women. I have reshaped my data from long to wide. No problems with the transformation, per se. However, many of the variable names (which will become the stubs) already end in a numeral, and my j variable is numeric, ranging from 1-10. I would like to avoid having variable "ev902", for example, from becoming ev9021, ev9022, ev9023,...ev90210 in wide form. I would much prefer to have the suffix to my variables be _j, rather than just the j variable (i.e. producing ev902_1, ev902_2, ev902_3, ... ev902_10 in the above example).
Is there a way to specify that in the reshape command? Does the key to doing this lie in making my j variable a string variable? If so, how should I approach that?
My current code is as follows:
evid ranges in values from 1 to about 10.
ev9* is a list of variable stubs that go from ev900-ev917. There are 3 or 4 instances where there is ev902 and ev902a.
It also may be helpful (or not) to know that:
Kerry MacQuarrie
I am working with data on women's contraceptive histories. In long form, cases are episodes of contraceptive use or non-use. In wide form, cases are women. I have reshaped my data from long to wide. No problems with the transformation, per se. However, many of the variable names (which will become the stubs) already end in a numeral, and my j variable is numeric, ranging from 1-10. I would like to avoid having variable "ev902", for example, from becoming ev9021, ev9022, ev9023,...ev90210 in wide form. I would much prefer to have the suffix to my variables be _j, rather than just the j variable (i.e. producing ev902_1, ev902_2, ev902_3, ... ev902_10 in the above example).
Is there a way to specify that in the reshape command? Does the key to doing this lie in making my j variable a string variable? If so, how should I approach that?
My current code is as follows:
Code:
reshape wide ev004 ev9* cmcclock eventorder endmo startmo startstate, i(survey v001 v002 v003 caseid) j(evid)
ev9* is a list of variable stubs that go from ev900-ev917. There are 3 or 4 instances where there is ev902 and ev902a.
It also may be helpful (or not) to know that:
- I am working with standard recode files in which the variables named ev004-ev917 follow a standard and documented naming convention, with which I and my co-researchers are quite familiar. I am, therefore, reluctant to rename the variables ending in numerals. (The variables with more descriptive variable names are ones we've created specifically for this analysis.)
- The above code is contained within a loop that is performing this reshaping on a set of 12 datasets. The number of women ranges from about 6,000-21,000 and the values on evid range from 1-5 to 1-10 in these datasets.
Kerry MacQuarrie
Comment