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 command without a j( ) variable using Stata 8


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: reshape command without a j( ) variable using Stata 8
Date   Tue, 15 Feb 2011 18:13:23 +0000

One spurious parenthetic pair (). -egen- is just -egen-, but the () otherwise flag -egen- functions which are called by -egen-. 

Nick 
[email protected] 


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 15 February 2011 16:52
To: '[email protected]'
Subject: RE: st: reshape command without a j( ) variable using Stata 8

Look at the help for -egen()-. -total()- lets you sum X by patient; -tag()- lets you report each patient just once. 

Nick 
[email protected] 

Karen Rappaport

My data is a long data set that contains information about a substance (X) in 
supplements, including multi-purpose vitamins and other supplements some 
patients take. Each supplement a patient takes that contains X is a separate 
observation. (I deleted from the data set all supplements that do not contain X, 
which I was able to do because I had a variable that was an "ingredient 
variable".) I want to calculate the amount of X patients are getting through 
supplements. In cases in which patients are getting X through only one 
supplement, it will be easy to instruct stata to calculate the amount of X 
consumed. But some patients are taking two or more supplements that contain X. 
Their unique patient numbers appear in the data set as many times as the number 
of different supplements they take that contain X.

I want to make the data set wide so that it looks something like this:

Patient_1  MedID_A   Medic_A  Days_90_A . . . MedID_B   Medic_B   Days_90_B. . . 


Right now, my data set looks like this:

Patient_1   MedID   Medic    Days_90 . . .
Patient_1   MedID   Medic    Days_90 . . .

Hope this helps!

Is there another command I might use instead of "reshape"?

From: Nick Cox <[email protected]>

It's not that clear that this will benefit much from -reshape-. In any
case the -reshape- syntax requires you to specify stubnames, not
variable names, so not knowing -j()- is not your only problem. The key
questions are: What is you want to do that you think will be easier
after a -reshape-? What do you want to do that seems difficult with
your present data structure?

On Tue, Feb 15, 2011 at 1:47 AM, Karen Rappaport
<[email protected]> wrote:

> I  have a data set that I want to reshape from long to wide using Stata 8.  It
> contains 2748 unique respondent sequence numbers and a total of 3191
> observations. It is a data set of patients and medications they take.  Some
> patients take two medications.
> Here are the variables:
> seqn (unique patient number; numeric)
> medID (medication ID number; string)
> medic (medication name; string)
> days90 (number of days medication taken in last 90 days; numeric)
> days30 (number of days medication taken in last 30 days; numeric)
> quant (quantity of medication taken daily)
> serving (label serving size; double)
> reason (reason for taking medication; double)
>
> At first, I thought this would be a straight forward case of reshaping "long 
to
> wide" with more than one variable.
>
> reshape wide medID medic days90 days30 quant serving reason ,  i(seqn) j( ??? 
)
>
> Essentially, all variables are shaped long to  wide so that I have only one 
set
> of observations per patient or "seqn".  (Is this essentially correct?) But 
what
> do I put in the j(  ) position?

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



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

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

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