问题
My variables in Stata are of the form:
First Name: Allen
Last Name: Von Schmidt
Birth Year: 1965
County: Cape May
State: New Jersey
First Name: Lee Roy
Last Name: McBride
Birth Year: 1967
County: Cook
State: Illinois
I would like to outsheet them to create comma separated rows in a .txt as:
Allen,Von Schmidt,1965,Cape May, New Jersey
Lee Roy,McBride,1967,Cook, Illinois
How can I use outsheet (or another command) to do this? Do I need to make the numerics into strings first? Do I need to add a commas to each variable first? Thanks!
Would something like the following work?
outsheet first last birth_year county state using FileName.txt, comma nolabel noquote
If I wanted to do the same thing but have the variables be " " separated would I remove the noquote in that previous stata code?
For example, suppose I might, instead, want an output of:
"Allen","Von Schmidt","1965","Cape May","New Jersey"
回答1:
This looks more like a job that you would want to do with the file
command, to keep full control over what is written to your file (especially if you have some possibly problematic ASCII characters like accents, which are common in names). See h file
for the details.
I am not sure that I understand exactly what you have in your dataset, and in what format, so I will refrain from writing up a working example that would not fit your setup. The file
command, however, is pretty straightforward (you can think of outsheet
as a wrapper for it).
来源:https://stackoverflow.com/questions/14923255/outsheet-to-create-a-comma-separated-txt