Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: outfile-ing multiple lines


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: outfile-ing multiple lines
Date   Fri, 20 Sep 2002 13:45:34 +0100

E. Michael Foster

>   I need to write out multiple (three) lines of information 
> for a single
> record.  Some of the same variables would be repeated 
> across the lines of
> raw data.  (In case you're interested, I'm creating a file 
> with multiple
> data structures for aML.)
> 
>    Basically I need a file that looks like this:
> 	  id  counter  y1 x1 x2
>           id  counter  y2 x1 x3
>           id  counter  y3 x1 x4
> where counter identifies the different record types.  
> Currently, the data
> are in stata with one record per id.  X2, X3, X4 may not 
> have the same
> dimension.
> 
>  One option would be to create multiple raw data files and 
> to manually
> concatenate them.  I'm doing this now, but it's a bit of a 
> nuisance.  
> 
>   Is there a way to do this with -outfile-?

Write your own program with -file-, or try 

. preserve 
. expand 3 
. bysort id counter : replace y1 = y2[1] 
. by id counter : replace y1 = y3[1] 
. by id counter : replace x2 = x3[1] 
. by id counter : replace x2 = x4[1] 
. outfile id counter y1 x1 x2 ... 
. restore 

Nick 
n.j.cox@durham.ac.uk 
*
*   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