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

st: RE: post


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: post
Date   Wed, 27 Nov 2002 18:40:55 -0000

Pedro Martins
> 
> i want to save, in a while/do loop, certain observations of 
> a data set into another data set without closing the first 
> data set. it seems that -post- is the command i should use 
> but apparently i'm not following its syntax correctly.
> 
> in a do-file, i wrote:
> 
> postfile x1 x2 using filename, replace
> local i=1
> while `i' <=20 {
> here i change the sample and do things to variable y
> post x1 x2 if y==1
> local i=`i'+1
> }
> postclose 
> 
> x1 and x2 are the two variables i want to save in the 
> secondary dataset (without closing the primary one). can you help?!
> 

Think of -post- as writing one record (one 
line) to a file each time it is invoked. 
That may not be what happens physically, 
i.e. as far as your computer is concerned, 
but it is the way to think about -post-. 

Therefore, -post- must be given expressions, 
each of which is, or evaluates to, single numbers. 
Also they must be parenthesised. Otherwise, 
Stata's interpreter could see results like 

2  -1 

and get it into its little head to 
evaluate that output as an algebraic expression. 

You can only use -post- to write variables 
if you loop over observations and write 
values from each observation out one at a time. 
Your syntax requires Stata to be smart 
enough to guess that you want some current
value of -x1- and -x2- to be posted each 
time around the loop, but Stata needs 
that to be spelled out.  

For all that, it is not at all clear 
that -post- is what will serve you 
best. On this information, -outfile- 
seems more suitable. 

Nick 
[email protected] 

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index