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

From |
Margaret R Grove <margaret.r.grove@Dartmouth.EDU> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: customised output formats |

Date |
Wed, 26 Mar 2008 07:54:27 -0400 |

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?

Cheers

Dan

*

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

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

**Follow-Ups**:**RE: st: customised output formats***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: customised output formats***From:*"Daniel Exeter" <d.exeter@auckland.ac.nz>

- Prev by Date:
**st: Creating single characters from long strings** - Next by Date:
**Re: st: Creating single characters from long strings** - Previous by thread:
**st: RE: customised output formats** - Next by thread:
**RE: st: customised output formats** - Index(es):

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