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

# Re: st: digits difference between stata and mata

 From Nick Cox To "statalist@hsphsun2.harvard.edu" Subject Re: st: digits difference between stata and mata Date Tue, 14 May 2013 00:24:08 +0100

```I don't know what you understand here by "like regression" but formats
assigned by -format- are by definition display formats and have no
effect on what is stored and therefore no effect on the results of
calculation.

Among other arguments, numeric formats controlling the number of
decimal places shown in displays have no bearing on the binary
representation of numbers.

There are many discussions, including

http://www.stata-journal.com/article.html?article=dm0067

Nick
njcoxstata@gmail.com

On 13 May 2013 22:11, Wu Zhang <wuzhang50@yahoo.com> wrote:
>
> Thanks!
>
> By the way, does the format change the calculation results, like regression?
>
> ________________________________
> From: Nick Cox <njcoxstata@gmail.com>
>
> 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
> njcoxstata@gmail.com
>
>
> On 13 May 2013 07:50, Wu Zhang <wuzhang50@yahoo.com> 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/
```