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

st: RE: outfile question

From   "Nick Cox" <>
To   <>
Subject   st: RE: outfile question
Date   Thu, 21 Nov 2002 16:05:13 -0000

Peter Adamson
> I am wanting to output variables to a text file for use by 
> another program.
> The format of the stata data file is something like:
> var1%9.0g var2%9.0g var3%9.0g etc ...
> and the format I want is:
> var1%9.0g
> var2%9.0g var3%9.0g etc ...
> Is there a way to do this using the outfile command?  
> Ideally I want to
> write a Carriage Return character to the file to force a 
> new line.  Any suggestions welcome!

I am not sure that -outfile- will help here. 

An alternative is to knit your own. 

program def myout 
	version 7
	syntax varlist using 
	tokenize `varlist' 
	local first "`1'" 
	mac shift 
	local varlist "`*'" 
	tempname out 
	file open `out' `using', w
	local N = _N 
	forval i = 1 / `N' { /* MS bug */ 
		file write `out' %9.0g (`first'[`i']) _n 
		foreach v of local varlist { /* MS bug */  
			local outlist "`outlist' %9.0g (`v'[`i'])" 
		file write `out' `outlist' _n 
		local outlist 
	file close `out'


myout var1 var2 var3 using myout.out 

should put the first variable value on one line 
and the other values on the next line. 

*   For searches and help try:

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