Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: reshape problem


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: reshape problem
Date   Sun, 20 May 2012 09:48:34 +0100

See

FAQ     . . . . . . . . . . . . . . . . . . . . . . . .  Problems with reshape
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        12/03   I am having problems with the reshape command. Can
                you give further guidance?
                http://www.stata.com/support/faqs/data/reshape3.html

for a ragbag of difficult -reshape- examples.

My guess is that this requires two -reshape-s, both -long-. This may help.

* sandpit to play in
clear
set obs 24
forval i = 1/23 {
gen id`i' = `i'
forval j = 1/3 {
gen var`j'_`i' = runiform()
}
}

* nitty-gritty
gen time = _n
reshape long id , i(time)
drop _j
reshape long var1_ var2_ var3_, i(id time)


On Sun, May 20, 2012 at 1:49 AM, Richard Hiscock
<[email protected]> wrote:

> I have a repeated measures data set (for time with 24 hour points) and three continuous measures for each of 23 subjects. Unfortunatly these have been presented to me (via spreadsheet) arranged as
>
>
> rows               24 time points, one point is a single row
> columns            groups of 4 x 23 subjects given as    id1 var1_1  var2_1 var3_1      id2 var1_2 var2_2 var3_2      id3 var1_3 etc
>
> I have managed to create a dataset in long form by forming individual data sets for each id (using keep), then renaming the three variables in each dataset, to be the same across the datasets, and then appending them together. This being possible only because the data only involves 23 individuals.
> I have looked at the reshape command but cannot see how it can be used with this arrangement.
> Is there another way to achieve this as the method used is not only tedious but clearly not easliy done as the number of individuals increase?

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index