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   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: reshaping help
Date   Tue, 25 May 2010 20:15:40 -0500

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/


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