Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: transpose a variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: transpose a variable
Date   Mon, 15 May 2006 11:50:33 +0100

If the identifier is missing on lines 2 to whatever
of each block, you would need to fill in the missings
_before_ you did this. Otherwise your dataset will
be messed up. 

The fill in is just

replace identifier = identifier[_n-1] if mi(identifier) 

Nick 
n.j.cox@durham.ac.uk 

Ada Ma
 
> You can use -reshape- as you say, but before you do it you need to
> generate a variable which shows which record the obs correspond to
> amongst all the obs you have for each person, something like the count
> variable in here:
> 
> identifier   dob             request      count
> ss12345   10 04 68     MA4          1
>                                  A2             2
>                                  ST69979    3
>                                  verygood    4
> ss12346    21 3 52     .                 1
> ss12347    14 8 71     MA2           1
> 
> You said you don't care about the particular order of the request
> variable so you can write:
> 
> bys identifier: gen count=_n
> reshape wide request, i(identifier) j(count)
 
> On 5/15/06, Eamonn O'Brien <Eamonn.O'Brien@icr.ac.uk> wrote:
> > I have a data set that I would like to 'reshape' to a 
> record per row.
> > All variables except one, the 'request' variable are on a 
> single row per
> > identifier. The request variable can be any number of rows 
> and contains
> > both string and numeric data, with the codes I am interested in
> > appearing in no particular order in the column.   I would like to
> > reshape this variable so it's on one row with the identifier. I have
> > explored -xpose- and -sxpose- and reshape but cannot achieve this.
> > (Their are more than 3 variables in the data set).
> >
> > identifier   dob             request
> > ss12345   10 04 68    MA4
> >                                   A2
> >                                   ST69979
> >                                   verygood
> > ss12346    21 3 52     .
> > ss12347    14 8 71     MA2
> >

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index