Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Airey, David C" <david.airey@vanderbilt.edu> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | re: st: data management question |
Date | Fri, 15 Oct 2010 15:22:20 -0500 |
. Thanks Nick and Eric. I ended up with something equivalent to what is below, before seeing Eric's post: sysuse auto collapse (mean) mpg weight /// (sem) sem_mpg=mpg sem_weight=weight /// (count) n_mpg=mpg n_weight=weight, by(foreign) order foreign mpg sem_mpg n_mpg weight sem_weight n_weight outsheet using data.txt, nonames replace /* open files to read and write */ tempname myfile // makes closing files automatic tempname mydata file open `myfile' using test.txt, write text file open `mydata' using data.txt, read text /* write header info */ file write `myfile' "# comment1" _newline file write `myfile' "# comment2" _newline file write `myfile' "@format=column" _tab file write `myfile' "mpg" _tab file write `myfile' "SE" _tab file write `myfile' "N" _tab file write `myfile' "weight" _tab file write `myfile' "SE" _tab file write `myfile' "N" _newline /* read outsheeted data from data file and write to text file */ file read `mydata' line while r(eof) == 0 { file write `myfile' `"`line'"' _newline file read `mydata' line } /* close files */ file close `mydata' file close `myfile' * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/