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]
st: RE: ODBC vs. insheet variable format troubles (importing SQL data)
From
"David Radwin" <[email protected]>
To
<[email protected]>
Subject
st: RE: ODBC vs. insheet variable format troubles (importing SQL data)
Date
Wed, 23 Jan 2013 13:51:21 -0800 (PST)
I don't think it will help with storage formats, but you can save display
formats and variable and value labels (assuming ODBC can import or create
them) using Roger Newson's -descsave- (SSC).
http://www.stata.com/statalist/archive/2013-01/msg00257.html
David
--
David Radwin
Senior Research Associate
MPR Associates, Inc.
2150 Shattuck Ave., Suite 800
Berkeley, CA 94704
Phone: 510-849-4942
Fax: 510-849-0794
www.mprinc.com
> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Abe N
> Sent: Wednesday, January 23, 2013 1:07 PM
> To: [email protected]
> Subject: st: ODBC vs. insheet variable format troubles (importing SQL
> data)
>
> Hello Everyone,
>
> Basically wondering if there is a way I can conserve variable data
formats
> when I bring data manually from SQL to STATA using insheet (see below
for
> more explanation and trouble I had with ODBC).
>
> I was originally told by the people maintaining the SQL database to use:
>
> odbc load, exec("Select command here") dsn("databasename") lowercase
>
> to bring data into STATA, which seemed to be working great for my
purposes
> until I did a duplicates report and found that I had way too many
> duplicates. After cross-checking by record_id (unique) with the
original
> SQL data I found the odbc command wasn't importing data properly. I had
> already set up the variable list though (some were too long so I had to
> manually rename them), so I used describe and I think display
> "`r(varlist)'", copied that varlist to a text file for what I would do
in
> my next step using insheet.
>
> Basically, ran my SQL query in SQL Server Management Studio 2008 R2,
saved
> the results/data as a tab delimited text and used:
>
> insheet (list of 160 variables) using data.txt, tab
>
> Which seems to be working great. The only problem I'm having now is
that
> while odbc maintained the variable data formats (string vs double, etc
> from SQL), this new method doesn't and it would be much easier for me if
> it didn't convert some of my strings into numbers, etc.
>
> So what I'm wondering is if there's a way I can sort of generate the
> variables, their data formats, and labels using my original odbc method,
> clear out that incorrect data, and then pull in data from the text file
> afterward? If not, is there a way I can carry over at least the
variable
> labels quickly rather than manually doing all 160 or so?
>
> Sorry for the long winded explanation, but hope the situation/question
> gets across clearly.
>
> Best,
> Abe Noorbakhsh
> [email protected]
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/