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

st: Re: CSV output ("bugs")?


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: CSV output ("bugs")?
Date   Fri, 5 Nov 2004 10:10:20 -0500

A bit easier with the file command:

program drop _all
*! csvout CFBaum 05nov2004
program csvout, rclass
syntax varlist(numeric max=1) [if] [in] using/, [Replace K(int 5)]
tempname hh
tempvar n
file open `hh' using `using', write `replace'
marksample touse
qui gen `n' = _n if `touse'
su `n', mean
local ii 0
forv i= `=r(min)'/`=r(max)' {
file write `hh' (`varlist'[`i'])
local ++ii
if (mod(`ii',`k')>0 & `i'<`=r(max)') {
file write `hh' ", "
}
else {
file write `hh' _n
}
}
file write `hh' _n
file close `hh'
end

This version will handle if and in qualifiers, and write 5 per line in CSV format unless otherwise directed with the k option: e.g.

csvout price using junk if n>25 & n<64,replace k(7)

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html

On Nov 5, 2004, at 2:33 AM, Al wrote:


I do have a rudimentary program for writing out all observations of a
variable with commas as separators and putting as many on a line as you
desire - so you can then paste this into a bugs .odc page. Of course you are
responsible for sorting the data in the approriate order.

Here it is: The first argument is the variable name; the second ones is the
number of observations per line of output.
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index