Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: data management question


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: data management question
Date   Fri, 15 Oct 2010 17:36:35 +0000

<>

You could also use Nick Cox's -filei- (from SSC) to add some comments/lines to the top of the file.
For the issue with the "x"'s, you could -tostring- your data while it's in Stata and replace the missings with "x" before you -outsheet- it to Excel.

**example**
sysuse auto, clear
drop length turn
**
ds, has(type numeric)
foreach x in `r(varlist)' {
	tostring `x', replace
	cap replace `x' = "x" if `x'=="."
	}
outsheet using "test.txt", replace nonames
**if needed: use option nonames to get rid of varnames**

 filei - "@format=column var1 se n var2 se n var3 se n" "test.txt"
  filei - "# my comments here3" "test.txt"
   filei - "# my comments here2" "test.txt"
    filei - "# my comments here1" "test.txt"
****

- Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754

On Oct 15, 2010, at 11:40 AM, Airey, David C wrote:

> .
> 
> I need to automate the creation of many tab delimited text (ascii) files.
> 
> The structure is:
> 
> # comments
> # comments
> # comments
> # comments
> @format=column var1 se n var2 se n var3 se n
> 1 10 2 8 50 5 8 x x x
> 2 11 1.9 8 50 5 8 30 3 8
> 3 12 1.7 8 50 5 8 30 3 8
> 4 13 2 8 50 5 8 30 3 8
> 5 18 2.1 8 50 5 8 30 3 8
> 
> etc
> 
> Problems with this file format are use of "x" for missing, column naming 
> conventions not compatible with Stata (@ symbol, repeated column names), 
> use of # for header comments.
> 
> -Outfile- or -outsheet- can export the data from underneath 
> the @ line just fine, and maybe -filefilter- can change the missing data to "x" as 
> needed. Should -file- be somehow used to create the file up to the @ line and then 
> -outsheet- below and then somehow join the two?
> 
> How do others handle the creation of data files that have nonstandard header text?
> 
> -Dave
> 
> 
> 
> *
> *   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/




*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index