Statalist


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

RE: st: customised output formats


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: customised output formats
Date   Wed, 26 Mar 2008 12:00:39 -0000

On second thoughts, Margaret seems to have the question the right way
round in that you want this as output. Sorry for my misreading. Still,
as Svend said, the opposite is an engaging puzzle.

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

Margaret R Grove

Daniel,

I'm not quite clear on what your "archaic program" consists of - do you 
have a Stata dataset which you are trying to reformat for other 
software?  I saw the other solutions but I'm seeing the problem a little

differently assuming that you want to go from a normal dataset to a 
special format for the other software.

If that's the case, you could do something like the following to make 
space for the "PID" and "END" records:

sort pid
expand 2 if pid==pid[_n-1]        *** Adds record for identifier only
expand 2 if pid!=pid[_n+1]         ***Adds record for "END" only
replace pid="END" if pid!=pid[_n+1]

foreach v of varlist x y {
    replace `v'=. if pid!=pid[_n-1]
}

and then do whatever other formatting you need and output to a txt file.

Meg

Daniel Exeter wrote:
> Hi there 
>
> I have the variables 
> Pid, x, y, t, d
>
> For 1000 participants, and there are many observations for each
> participant. 
>
> I'm using an archaic program that uses data in the format:
>
> Pid
> X,y
> X,y
> X,y
> END
> Pid
> X,y
> X,y
> END 
>
> And so on.
>
> I would think that I need to : 
>
> loop through for each pid
>   identify the value of pid
>   write this value to an outfile
>
>  loop through all observations of current pid
>   extract values for x and y
>   write x and y values to outfile
>  
> write "end" into outfile
>
> I tried this logic, but I can't seem to append info to the outfile...
> any ideas?

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