Statalist The Stata Listserver


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

st: RE: writing output to ASCII file


From   "Peter J. Burke" <[email protected]>
To   <[email protected]>
Subject   st: RE: writing output to ASCII file
Date   Tue, 3 Oct 2006 13:08:10 -0700

Scott,
	If there is no output, then check to be sure that the last line of
code is followed by a carriage return. It looks like the file close
statement is not executing. The code works on my computer.
Peter 


Peter J. Burke
Professor
Department of Sociology
University of California
Riverside, CA 92521-0419
Phone: 951/827-7004
Fax: 951/827-3330
[email protected] 
http://wat2146.ucr.edu


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Scott Cunningham
Sent: Tuesday, October 03, 2006 11:54 AM
To: [email protected]
Subject: st: writing output to ASCII file

I am creating a table of summary statistics for individuals of  
different ages.  The data is from the National Longitudinal Survey of  
Youth 1997 (NLSY97), and the age of the individual range from 12 to  
23 (for my dataset, that is; respondents are older in the most recent  
waves).  I am calculating the number of sex partners individuals  
reported having in the last year, by age, using nested loops and the - 
file- command to store the output.  Below is my short program, which  
is very close to the one that Austin Nichols posted here a week or so  
ago wherein he recommended going this route to create and store so  
many statistics.  When I run this, it calculates the stats I need  
without trouble, but it does not appear to be storing them.  It is  
creating a file entitled sum.txt, but the file is empty.  So I assume  
the problem lies in the -file write...- code, or possibly with the  
nested loops themselves.  Can anyone see where I might be going wrong?

thanks,


scott

**

cap file close o
file open o using sum.txt, write replace
forv a=12/23 {
file write o _tab "`a'"
}
foreach v of varlist rp {
forv a=12/23 {
su `v' if age==`a', detail
local m`a'=r(mean)
local sd`a'=r(sd)
local n`a'=r(N)
local q50`a'=r(p50)
local q75`a'=r(p75)
local q90`a'=r(p90)
local q95`a'=r(p95)
}
file write o _n "`: var lab `v''" _tab
foreach stat in m sd n q50 q75 q90 q95 {
forv a=12/23 {
   file write o _tab "``stat'`a''"
}
}
file write o _n _tab
}
file close _all
*
*   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/



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