Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: how to transpose few variables with their values


From   "Sebastian F. B�chte" <[email protected]>
To   [email protected]
Subject   Re: st: how to transpose few variables with their values
Date   Fri, 13 Apr 2007 09:42:00 +0200

Pritpal,

maybe the following is doing what you want:

gen first=""
gen second=""
gen third=""
foreach var of varlist Brand* {
	replace first = "`var'" if `var'==1
	replace second = "`var'" if `var'==2
	replace third = "`var'" if `var'==3
}

Afterwards you may drop all other variable but first, second, and third.

Regards
Sebastian

On 4/13/07, Pritpal Marjara <[email protected]> wrote:
In a multiple choice question in a population based survey, I have asked for
the top three preferred brand of health services.

The total number of codes are twelve in number to choose from.  At the time
of data entry, the data was entered as twelve variables of brand names as
columns.  For each case, nine of the variables thus have missing values and
remaining 3 variables  have 1,2 or 3 numerical value as a preference in
order.    I am wondering if there is any way to transpose these twelve
variables with the values without affecting remaining 300+ variables in the
database.

For example, the data now is;

ID#     Brand1  Brand2  Brand3  Brand4  Brand5  Brand6  Brand7  ....
001     -               3               -               1               -               2               -
002     1               -               -               2               -               3               -
003     -               1               3               -               2               -               -

And, I wish if the data would look like;

ID#     first           second  third

001     brand4  brand6  brand2
002     brand1  brand4  brand6
003     brand2  brand5  brand3


I am using Stata 8 version.

Appreciate guidance from the group in resolving this in a simpler way.


Thank you,

Pritpal

*
*   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/



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