Statalist


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

Re: Re: st: why -odbc- made error?


From   [email protected]
To   statalist<[email protected]>
Subject   Re: Re: st: why -odbc- made error?
Date   Sat, 01 Aug 2009 01:31:04 +0800

Joseph, thank you very much again.

Through the second suggestion, the result is correct. Thank you.
By the way, can the two lines of code you posted be applied to all 
excels-reading in the stata?

odbc load, dsn("Excel Files;DBQ=xxx.xls;") ///
exec("SELECT * FROM [Excel 8.0;HDR=YES;IMEX=1;Database=xxx.xls;].[1998$];")





----- Original Message -----
From: Joseph Coveney <[email protected]>
To: <[email protected]>
Subject: Re: st: why -odbc- made error?
Date: 2009-7-31 23:51:22

Rose wrote:

Thank you very much for your reply!
Now that sometimes errors indeed exist,
I will consider other methods instead of openning EXCEl directly in the stata.

--------------------------------------------------------------------------------

Before trying tedious or complicated other methods, consider a couple of
experiments to see if they fix the problem.

First:

By default, ODBC scans only the first eight rows in order to guess the datatype
(numeric or text). Your variable c was empty for the first eight rows, and ODBC
might have assumed that the blank cells would be text.

Try specifying the rows to scan in the DSN string as follows to see whether it
works for your dataset:

odbc load, table(1998$) dsn("Excel Files;DBQ=xxx.xls;MaxScanRows=16;")

Second:

If that doesn't work, then try the workaround--it's not very complicated,
actually only two lines of code:

odbc load, dsn("Excel Files;DBQ=xxx.xls;") ///
exec("SELECT * FROM [Excel 8.0;HDR=YES;IMEX=1;Database=xxx.xls;].[1998$];")
destring x-c, replace

Joseph Coveney


*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index