Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: splitting columns


From   "Katsuhide Isa" <CQB01114@nifty.ne.jp>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: splitting columns
Date   Thu, 28 Nov 2002 11:16:36 +0900

I have a survey data which has the following structure.
Each column contains the result of a survey question
that allows MA(multiple answer).

* data1
Q1 Q2 Q3 Q4
1 1 1 …
2 2 2 
3 3 12 
12 4 1 
13 5 1 
23 12 2 
123 24 1 
13 14 2 
23 125 12 
2 234 1 
… … … 

In the example above, Q1 has three choices,
Q2 five choices, and Q3 two choice.
But, it should have been typed as below:

* data2
Q1_1 Q1_2 Q1_3 Q2_1 ...
1 0 0 1
0 1 0 0
0 0 1 0
1 1 0 0
1 0 1 0
0 1 1 1
1 1 1 0
1 0 1 1
0 1 1 1
0 1 0 0
… … … 
Q1_1 indecates the 1st choice of Q1, Q1_2 the 2nd 
choice, and so on.
That is, I'd like each variable to take on one if a 
relevant choice is selected.

The question is, is it possible to convert the data1 into 
data2 from within Stata?
One immediate solution would be to create new 
variables using -generate- as below (in the case of 
three choices):

gen Q1_1 = 1 if Q1 == 1 | Q1 == 12 | Q1 == 13 | Q1 == 123
gen Q1_2 = 1 if Q1 == 2 | Q1 == 12 | Q1 == 23 | Q1 == 123
gen Q1_3 = 1 if Q1 == 3 | Q1 == 13 | Q1 == 23 | Q1 == 123

But this method is rather troublesome(the maximum 
number of choices is seven, and there are as many as 
more than 80 questions in the original data!) and easy 
to mistype.
I'd like to know if there is some better way to do the 
same thing.

Any suggestions welcome.
Thanks in advance.

K.I.











*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index