Bookmark and Share

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]

Re: st: RE: Column types for ODBC


From   Michael Ewens <[email protected]>
To   [email protected]
Subject   Re: st: RE: Column types for ODBC
Date   Fri, 21 May 2010 11:06:10 -0700

The goal is to keep the Stata internal data type as a date (which is just a numeric), but send it to the odbc command as date-readable by mysql/Access/etc. If Stata could send the 'odbc insert' the formatted date

"1Jan2000"

rather than its numeric counterpart, it would be a lot easier to work with Stata-exported odbc dates. As is, it appears that databases created with Stata's odbc inserts were not built for use outside of Stata (my example is Stata creates a MySQL database and R loads it). That of course is not a bug or defect, just an important caveat when working with 'odbc.'

Michael

Martin Weiss wrote:
<>

" Is there a way to force the create option to use
particularl column types?"


In Stata parlance, these are data types. The whole array can be seen in
-help data_types-. -generate- accepts them as "arguments", as in -gen str10
myvar="hello"- for a string of maximum length 10.


HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Michael Ewens
Sent: Freitag, 21. Mai 2010 19:50
To: [email protected]
Subject: st: Column types for ODBC

Dear all:

I am inserting columns of Stata-formatted dates into an ODBC database
(MySQL).  If one runs

--
gen date = mdy(month,year,date)
format date %td
odbc insert, dsn(datasource) t(test) u(u) create sqlshow
--

Stata creates a 'float' column in the new table.  If one wants to
subsequently use this new table outside of Stata, the date information
is effectively lost.  Is there a way to force the create option to use
particularl column types?

My current workaround first converts the 'date' variable to a string
'YYYYMMDD.'  The next step could be to run something like

--
odbc exec("ALTER TABLE test MODIFY date DATE"), dsn(datasource) u(u)
--

Unfortunately, this approach requires a line of code for all the date
variables in the data.  Is there a better approach to dealing with dates
and odbc?  Ideally, the 'datestring' option available for 'odbc load'
would be available for 'odbc insert'.

Best,
Michael
*
*   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/
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index