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 wide to long
From
Scott Merryman <[email protected]>
To
[email protected]
Subject
Re: st: reshape wide to long
Date
Thu, 10 Apr 2014 21:12:58 -0500
Try adding the -string- option
. clear
. input id kcalpre kcalpost
id kcalpre kcalpost
1. 1 5620 3910
2. 2 5470 4220
3. 3 5640 3885
4. end
. reshape long kcal , i(id) j(t) string
(note: j = post pre)
Data wide -> long
-----------------------------------------------------------------------------
Number of obs. 3 -> 6
Number of variables 3 -> 3
j variable (2 values) -> t
xij variables:
kcalpost kcalpre -> kcal
-----------------------------------------------------------------------------
. l
+------------------+
| id t kcal |
|------------------|
1. | 1 post 3910 |
2. | 1 pre 5620 |
3. | 2 post 4220 |
4. | 2 pre 5470 |
5. | 3 post 3885 |
|------------------|
6. | 3 pre 5640 |
+------------------+
Scott
On Thu, Apr 10, 2014 at 8:32 PM, Michael McCulloch
<[email protected]> wrote:
> Hello, I am trying to reshape the following dataset from wide to long:
>
> id kcalpre kcalpost
> 1 5620 3910
> 2 5470 4220
> 3 5640 3885
>
> with the command:
> . reshape long kcal, i(id) j(timing)
>
> I am receiving an error message:
> variable timing contains all missing values.
>
> I have specified:
> - long is the type of reshaping
> - kcal is the stem of the two variables I want to convert from wide to long: kcalpre and kcalpost
> - i(id) uniquely identifies each variable in the wide format
> - j(timing) is to specify that the suffix of kcal (pre and post) should be placed in the variable called -timing-
>
> It seems I've followed the help file and tutorials. I'd appreciate any advice or corrections.
>
>
> Best wishes,
> Michael McCulloch
>
> --
> Pine Street Foundation, since 1989
> 124 Pine Street | San Anselmo | California | 94960-2674
> P: (415) 407-1357 | F: (206) 338-2391 | http://www.PineStreetFoundation.org
>
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/