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

st: RE: post

From   "Pedro Martins" <>
To   <>
Subject   st: RE: post
Date   Wed, 27 Nov 2002 19:06:39 +0000

thank you for this.
but is it possible to use the -append- option in -outfile-?

Pedro Martins
Department of Economics
University of Warwick
Coventry CV4 7AL
United Kingdom

Tel: +44/0 24765 28418
Fax: +44/0 24765 23032

>>> 11/27/02 06:40PM >>>
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. 


*   For searches and help try:

*   For searches and help try:

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