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: reshaping help


From   "Paul O'Brien" <[email protected]>
To   [email protected]
Subject   Re: st: reshaping help
Date   Wed, 26 May 2010 07:27:56 +0100

thanks scott for this.

however, i run into a problem early on:

. reshape long  np p t, i(id) j(foo) string
(note: j = 1 2)
 np1 implied name too long

i do not understand this.

paul

On 26 May 2010, at 02:15, Scott Merryman wrote:

> Like this?
> 
> clear*
> input str8 study   day   str3  t1     str5 t2      p1      np1
> all1    p2      np2     all2
> "Ho&Kwan" 1       "LNG"     "Yuzpe"   3       214     217     4
> 213     217
> "Ho&Kwan" 2       "LNG"     "Yuzpe"   6       124     130     4
> 110     114
> "WHO"     1       "LNG"     "Yuzpe"   2       448     450     9
> 450     459
> "WHO"     2       "LNG"     "Yuzpe"   4       334     338     15
> 355     370
> end
> 
> gen id = _n
> reshape long  np p t, i(id) j(foo) string
> drop id foo all*
> 
> rename p pop1
> rename np pop2
> gen id = _n
> sort st t d
> reshape long pop , i(id) j(p)
> replace p =  mod(p,2)
> gsort study  t -p
> drop id
> l, sepby(study)
> 
> 
> Scott
> 
> 
> On Tue, May 25, 2010 at 4:40 PM, Paul O'Brien <[email protected]> wrote:
>> i find the reshape command difficult to use, and have tried many commands without success.
>> 
>> Study   Day     t1      t2      p1      np1     all1    p2      np2     all2
>> Ho&Kwan 1       LNG     Yuzpe   3       214     217     4       213     217
>> Ho&Kwan 2       LNG     Yuzpe   6       124     130     4       110     114
>> WHO     1       LNG     Yuzpe   2       448     450     9       450     459
>> WHO     2       LNG     Yuzpe   4       334     338     15      355     370
>> 
>> each row represents the day of treatment, the treatments (1 and 2), the number of pregnancies with each treatment, the number not pregnant and all exposed for each treatment.
>> 
>> i need each row to represent one day/treatment:
>> Study   Day     t       pop     p
>> Ho&Kwan 1       LNG     214     0
>> Ho&Kwan 2       LNG     124     0
>> Ho&Kwan 1       Yuzpe   213     0
>> Ho&Kwan 2       Yuzpe   110     0
>> Ho&Kwan 1       LNG     3       1
>> Ho&Kwan 2       LNG     6       1
>> Ho&Kwan 1       Yuzpe   4       1
>> Ho&Kwan 2       Yuzpe   4       1
>> 
>> so that i can then expand to get one observation per row.
>> 
>> i can do this in Excel but frequently need to reorganise summary trial data like this and want to do it in Stata, thinking there must be an easier way.
>> 
>> help appreciated.
>> 
>> thanks,
>> 
>> paul
>> 
> 
> *
> *   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/

-------------------------------
Dr Paul O'Brien
Raymede Clinic
Westside Contraceptive Services
Central London Community Healthcare
Exmoor St
London
W10 6DZ
UK
44 + (0)20 8962 4450









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