i don't know if this is the best way, but you could use the -xpose- command.
but before that you need to make all you variables numerical. for example:
/*coding males as 1 females as 0, Y as 1 no(missing) as 0 */
/*coding age as numeric age*/
forval i = 2/256 {
gen real_v`i' = 1 if v`i' == "M" | v`i' == "Y"
replace real_v`i' = 0 if v`i' == "F" | v`i' == ""
replace real_v`i' = real(v`i') in 2
}
/*now you no longer really need id and v1, as long as you make note of
what each row means*/
drop id v1
/*now you can transpose*/
xpose, clear
/*now you rename to get the variables name back*/
rename v1 sex
rename v2 age
...
/*now you label values*/
label define yesno 1 yes 2 no
label define gender 1 male 0 female
...
hope this helps. there are probably more elegant solutions though.
-radu
2006/5/4, Thomas Speidel <thomassp@cancerboard.ab.ca>:
Dear Statalisters:
I have a dataset that I need to re-organize in a long format.
Here is a sample:
+--------------------------------------+
| id v1 v2 v3 v4 |
|--------------------------------------|
| 2 Sex M M M |
| 3 Age 47 66 56 |
| 4 Left eye |
| 5 Right eye Y Y Y |
| 6 Lower eyelid Y Y Y |
|--------------------------------------|
| 7 Upper eyelid |
| 8 Lateral canthus |
| 9 Medial canthus Y Y |
| 10 Recurrent lesion |
| 11 Primary lesion Y Y Y |
+--------------------------------------+
There are 255 observations (v2-v256) occupying the columns. I need each
observation to be a distinct row. Almost all of the entries are string,
(missing means "NO"). I am having difficulties using the reshape command
to achieve my goal, possibly because of the strings. Any suggestion on
how to approach this? Should I create a loop to encode all variables?
Thanks for any suggestion,
Thomas
--
Thomas Speidel
Statistical Associate
Clinical Trials Unit
Tom Baker Cancer Centre
1331 - 29th Street N.W.
Calgary, AB, T2N 4N4
Tel. (403) 521-3370
Email: thomassp@cancerboard.ab.ca
This e-mail and any attachments may contain confidential and
privileged information. If you are not the intended recipient,
please notify the sender immediately by return e-mail, delete this
e-mail and destroy any copies. Any dissemination or use of this
information by a person other than the intended recipient is
unauthorized and may be illegal.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/