--- Alexander Tsai <[email protected]> wrote:
> This might be an easy question, but I'm not coming with any good
> solutions,
> and a search of the archive didn't yield any promising leads.
>
> I have a dataset of survey responses that looks like this:
>
> ID q1_e1 q1_e2 q2_e1 q2_e2 ... q20_e1 q20_e2
> 1 1 1 0 1 ... 1 1
> 2 0 0 1 1 ... 0 1
> ...
> 100 1 1 1 1 ... 1 1
>
> There are more variables in the actual data than I show in the above
> example. (Variables extend from q1_e3, q1_e4, q1_e5 ... to q20_e3,
> q20_e4, q20_e5.)
>
> I want the dataset to look like this:
>
> ID q e1 e2 e3 e4 e5
> 1 1 1 1
> 1 2 0 1
> ...
> 1 20 1 1
> 2 1 0 0
> 2 2 1 1
> ...
> 2 20 0 1
> ...
> 100 1 1 1
> 100 2 1 1
> ...
> 100 20 1 1
>
> I've been toying with -reshape- and -xpose- for days, but I've got
> nothing.
If the variable names were e1_q1, e2_q1, etc (i.e. reverse the e-part
and the q-part of the variable names) than this would be a
straightforward -reshape-. So, if the variable names are as structured
as they are in your example, than the easiest way to achieve what you
want is rename the variables, and than do the reshape.
*--------------- begin example --------------------
drop _all
input id q1_e1 q1_e2 q2_e1 q2_e2
1 1 1 0 1
2 0 0 1 1
end
forvalues wave = 1/2 {
forvalues question= 1/2 {
rename q`question'_e`wave' e`wave'_`question'
}
local waves = "`waves' e`wave'_"
}
reshape long `waves', i(id) j(question)
*---------------- end example ---------------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )
Hope this helps,
Maarten
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
___________________________________________________________
Want ideas for reducing your carbon footprint? Visit Yahoo! For Good http://uk.promotions.yahoo.com/forgood/environment.html
*
* 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/