Dear Stefan,
if you want to keep no more than 3-4 decimals, multiply your number by
1000, take integer part, and divide by 1000.
gen y=int(x*1000)/1000
Here y is the same as x, but with less precision.
Also try storing your data in floats, rather than doubles. This will
also mean storing your data more efficienty.
Hope this helps,
Sergiy Radyakin
On 5/13/08, [email protected] <[email protected]> wrote:
> Hi statalisters,
>
> I'm trying to establish ODBC-connections between Stata and a Firebird
> database (V: 2.1) under Win XP.
> The available ODBC-drivers are a bit outdated and not well documented. So I
> had to find out more or less by trial and error why I couldn't export float
> and double vars. The error is not a decimal point/comma issue but a issue of
> decimal places.
> The ODBC-driver is only capable of 18 decimal places while stata exports 20.
>
>
> So what happens:
> gen float age = 6
> odbc insert age , table(s1) dsn(firebird) create sqlshow
>
> ** ...leads to:
>
> CREATE TABLE s1 (age FLOAT)
> INSERT INTO s1 (age) VALUES (6.00000000000000000000)
> [ODBC Firebird Driver][Firebird]Dynamic SQL Error
> SQL error code = -104 Token unknown - line 1, column 30 6
>
> **********************************************************
>
> Cutting a value to 18 decimal places works:
>
> odbc exec("insert into s1 (age) VALUES (6.123456789012345678)"),
> dsn(firebird)
>
> ** ...leads to:
> insert into s1 (age) VALUES (6.123456789012345678)
>
>
> ****
>
> My question:
>
> Is there any way to reduce decimal places before ODBC export inside Stata (I
> need no more than 2 or 3 decimal places)
>
> There are workarounds (like export as string or export multiplied with 1000
> as an integer - with reconversion inside the database) but these are
> burdensome and error-prone in routine use.
>
>
> Best wishes
>
> Stefan Gawrich
> Dillenburg
> Germany
>
>
>
>
>
>
>
>
> *
> * 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/
>
> Privileged, confidential or patient identifiable information may be contained in this message. This information is meant only for the use of the intended recipients. If you are not the intended recipient, or if the message has been addressed to you in error, do not read, disclose, reproduce, distribute, disseminate or otherwise use this transmission. Instead, please notify the sender by reply e-mail, and then destroy all copies of the message and any attachments.
>
>
> *
> * 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/
>
*
* 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/