| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: how does insheet determine datatypes?
I'd like to add a little tangential comment.
Insheet, at least as it has been up to Stata 8, behaves ungracefully
if the second line contains var lables (and var names are in the
first line), which is how some raw datasets are composed. In this
case, you get everything as string -- usually very long ones. And
the var names in the raw data are ignored; you get default names v1,
v2, etc.. And what were supposed to be the var names and labels end
up as data in the first and second observations.
If you encounter this situation, you may want to use -convert_top_lines-.
ssc install convert_top_lines
This doesn't fix -insheet-, but cleans up the mess afterwards.
(I don't know if -insheet- has become more graceful in Stata 9; I
haven't yet made that leap.)
HTH.
--David
At 12:51 PM 1/6/2007, you wrote:
Insheet is indeed very efficient in finding the correct format of raw data.
The only situation giving problems for me is reading raw files with
a unique 10 digit person identifier. Handling this large integer as
a key in merge gives problems. To force the variable to a string
either create a dictionary or use the mechanism described by Bill
Gould, namely to have just one record where the column contains letters.
I edit the raw file manually by adding a record at the top after
variable names or (better) use stata to add that line:
cpr v1 v2 v3
0xx1201956 1 2 2 // this record will force the
first variable to string
0101201956 1 2 2
1101201954 1 2 1
etc .... rest of records
and then read as :
insheet using myfile
drop in 1
....and I have the cpr variable as a string without the "fake" record
Jens Lauritsen, MD, PhD
University of Southern Denmark
Odense University Hospital, Denmark
[...]
*
* 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/