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 wide with 'repeated' observations


From   "Ojinnaka, Chinedum" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: reshape wide with 'repeated' observations
Date   Wed, 19 Feb 2014 16:28:18 +0000

The data set looks something like this. 

studyid                        exer0       bldsugar0             diet0       footcare0       exer6       bldsugar6       diet6       footcare6       exer12       bldsugar12       diet12       footcare12   
1             		              5	        7.8	                 4                6         	            4	        	7.8	          12                6                     5	          8.5	       4                 6         
2           		              8	        10	                14                5        	            4	        	8	          6                10                     16	          7.9	    12                 3       

I will like to have the data in the long long form. The data also has dates but we are not necessarily interested in the dates. I tried to reshape to  long wide then long long (http://www.stata.com/bookstore/stata12/pdf/d_reshape.pdf pg. 14). 

Using the code reshape long exer bldsugar footcare diet,  i(studyid) j(interval), I was able to get the data to look like this

studyid                       interval           exer       bldsugar       diet       footcare       
1             		              0	     5   	7.8	4	6
1                                            6	     4	       7.8	          12                 6
1          		            12	     5	       8.5	            4                 6   
2		               0                    8	     10	          14                 5
2       		               6	     4	       8	            6               10
2         		             12	  16	       7.9             12                 3

However, we would like the data to be look like

Studyid                     interval              care                Score
1	0	e	5
1	0	b	7.8
1	0	d	4
1	0	f	6
1	6	e	4
1	6	b	7.8
1	6	f	12
1	6	d	6

I rename the exer bldsugar diet and footcare variables to eScore bScore dScore fScore so I can reshape to long long using the code reshape long @Score, i(studyid interval) j(care).

However, I got the error message 'variable selfcare contains all missing values'

So I do not know what else to do. Please, I would appreciate any clarification as to what I am doing wrong.

Thank you.

Chi-Chi





----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Tuesday, February 18, 2014 7:10 PM
To: [email protected]
Subject: Re: st: reshape wide with 'repeated' observations

First, you showed us nothing of R0 R6 R12 V0 V6 V12 before.

Second, R* V* look to me like wide form needing -reshape long- if 0 6
12 indicate times of day. I can't make sense at all of your description.

It might help if you tell us also what the variables mean. If these are days -- but every other day -- and hours -- but only 00:00 06:00 12:00, then that's puzzling, although not completely crazy. On the other hand, the R* V* might mean something quite different, in which case the data might not need any kind of -reshape-

Nick
[email protected]


On 18 February 2014 22:56, Ojinnaka, Chinedum <[email protected]>

> Other variables within the dataset are in wide format while this 
> particular variable is in long form i.e. the dataset looks like the 
> table provided below. So, I want to get the data in a wide form and 
> reshape it back to long accounting for all the variables that should 
> also be in a long form
>
>>> id      date                   level   R0     R6     R12     V0         V6   V12
>>> 1       02202004        5.6        3         5       4      7         5            2
>>> 1       04202004        5.4        3         5       4      7         5            2
>>> 1       06202004        5.6        3         5       4      7         5            2

Nick Cox

> OK; so why do you want to do that?

Ojinnaka, Chinedum <[email protected]> wrote:

>> I am sorry about the confusion. Yes, the data is in long form and I want to reshape it to a wide form. However, because some of the observations have similar values like in the table I provided. Stata says the values are not unique to the id. I am wondering if there is a way to get around this problem.

Nick Cox

>> Your title says "reshape wide" but you say you want to "reshape from wide to long". Stata means "reshape to wide" when it says "reshape wide" and similarly for "long".
>>
>> In your case, the example data appear to be already in long form with identifier repeated for each observation. For most panel or longitudinal tasks, this is what you need, so if I understand you correctly, there is no problem to be fixed.

On 18 February 2014 17:05, Ojinnaka, Chinedum <[email protected]

>>> I want to reshape a dataset from wide to long. The variable of interest is a measure that can be repeated multiple times with the same measurement (example provided in table below), thus, I received an error message saying that values of the variable are not unique within the studyid. Is there anything that can be done about this?
>>>
>>> id      date                   level
>>> 1       02202004        5.6
>>> 1       04202004        5.4
>>> 1       06202004        5.6

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


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