Bookmark and Share

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

[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" <>
To   <>
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).

David Radwin
Senior Research Associate
MPR Associates, Inc.
2150 Shattuck Ave., Suite 800
Berkeley, CA 94704
Phone: 510-849-4942
Fax: 510-849-0794

> -----Original Message-----
> From: [mailto:owner-
>] On Behalf Of Abe N
> Sent: Wednesday, January 23, 2013 1:07 PM
> To:
> 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
> when I bring data manually from SQL to STATA using insheet (see below
> 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
> until I did a duplicates report and found that I had way too many
> duplicates.  After cross-checking by record_id (unique) with the
> 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
> my next step using insheet.
> Basically, ran my SQL query in SQL Server Management Studio 2008 R2,
> 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
> 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
> 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
> *
> *   For searches and help try:
> *
> *
> *
*   For searches and help try:

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