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: digits difference between stata and mata


From   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: digits difference between stata and mata
Date   Mon, 13 May 2013 03:16:23 -0400

And the default formats for different data types are listed here:
http://www.stata.com/help.cgi?format

                        byte    %8.0g
                        int     %8.0g
                        long    %12.0g
                        float   %9.0g
                        double  %10.0g

On Mon, May 13, 2013 at 3:00 AM, Nick Cox <[email protected]> wrote:
> Please note: "Stata", "Mata", as at
>
> http://www.stata.com/support/faqs/resources/statalist-faq/#spell
>
> What you see is is likely just to be a side-effect of different
> default formats. You can arrange the same format. Look at -help
> format-.
>
> . sysuse auto
> (1978 Automobile Data)
>
> . gen gpm = 1/mpg
>
> . list gpm in 1/10
>
>      +----------+
>      |      gpm |
>      |----------|
>   1. | .0454545 |
>   2. | .0588235 |
>   3. | .0454545 |
>   4. |      .05 |
>   5. | .0666667 |
>      |----------|
>   6. | .0555556 |
>   7. | .0384615 |
>   8. |      .05 |
>   9. |    .0625 |
>  10. | .0526316 |
>      +----------+
>
> . mata
> ------------------------------------------------- mata (type end to
> exit) ---------------
>
> : gpm2 = st_data(., "gpm")
>
> : gpm2[(1..10)]
>                   1
>      +---------------+
>    1 |  .0454545468  |
>    2 |  .0588235296  |
>    3 |  .0454545468  |
>    4 |  .0500000007  |
>    5 |  .0666666701  |
>    6 |   .055555556  |
>    7 |  .0384615399  |
>    8 |  .0500000007  |
>    9 |        .0625  |
>   10 |  .0526315793  |
>      +---------------+
>
> : strofreal(gpm2[(1..10)], "%5.4f")
>              1
>      +----------+
>    1 |  0.0455  |
>    2 |  0.0588  |
>    3 |  0.0455  |
>    4 |  0.0500  |
>    5 |  0.0667  |
>    6 |  0.0556  |
>    7 |  0.0385  |
>    8 |  0.0500  |
>    9 |  0.0625  |
>   10 |  0.0526  |
>      +----------+
>
> : end
> -----------------------------------------------------------------------------------------
>
> . format gpm %5.4f
>
> . list gpm in 1/10
>
>      +--------+
>      |    gpm |
>      |--------|
>   1. | 0.0455 |
>   2. | 0.0588 |
>   3. | 0.0455 |
>   4. | 0.0500 |
>   5. | 0.0667 |
>      |--------|
>   6. | 0.0556 |
>   7. | 0.0385 |
>   8. | 0.0500 |
>   9. | 0.0625 |
>  10. | 0.0526 |
>      +--------+
>
> Nick
> [email protected]
>
>
> On 13 May 2013 07:50, Wu Zhang <[email protected]> wrote:
>
>>   I have a variable list which has different digits after being imported into MATA; I take a snap of the whole picture:
>>
>> In stata:
>>
>> --------------------------------------------
>> 1.  9.477003   8.210668     59.375    -2.00877
>> 2.   9.34036   9.473704    66.0647   -1.543392
>> 3.  8.986102   8.188967   53.92946   -.5894488
>> 4.  9.285332   9.773379   73.92938   -.2278635
>> 5.  9.286468   9.812742   57.82097   -.0813199
>>
>>
>>
>> While in MATA:
>>     1     9.477003098    8.21066761    59.375          -2.008770227
>>     2    9.340359688    9.473704338    66.0647049    -1.54339242
>>     3    8.986102104    8.188966751    53.92946243   -.5894488096
>>     4    9.285331726    9.773379326    73.92938232   -.2278635055
>>     5    9.286467552    9.812742233    57.82096863   -.0813199058
>>
>>
>> Note that what we see in STATA is the same as in the data editor view.
>>
>>
>> I am just wondering whether there is a way to make them the same?
> *
> *   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/


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