Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: digits difference between stata and mata


From   Sergiy Radyakin <serjradyakin@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: digits difference between stata and mata
Date   Tue, 14 May 2013 00:24:44 -0400

Wu,
the most recent version of spreg.ado available at SSC declares it was
last updated on 05aug2010 and the last update to Stata itself dates to
20mar2013, which means the code didn't change during the last two
weeks. Either your data has changed, or your procedure has changed. It
is probably not difficult to verify if the data has changed - your
other results should also differ. Have a look at the basic statistics.
If they didn't change either, then you are calling -spreg- differently
this time. To make sure your results are reproducible, careful
planning approach is absolutely required. To master .do files and
logging and other necessities, acquire the book by J. Scott Long "The
Workflow of Data Analysis Using Stata" (Amazon says 19 copies left at
the moment, so hurry up). If you have all the logs from the earlier
and the current run that differ, perhaps you could get a bit more
scientific about what is ~different~ in the results? A side-by-side
presentation of the command and results earlier and now could be just
what it takes.
Best, Sergiy

On Mon, May 13, 2013 at 10:23 PM, Wu Zhang <wuzhang50@yahoo.com> wrote:
> Hi Nick,
>
>   Thanks for your contribution to this list.
>   I have a very strange question: I used "spreg" to run spatial regression; in its manual that command is equivalent to a two-step method which can be implemented in Mata; I did the "spreg" and Mata two weeks ago and the results were the same. But when I repeated the process yesterday, the results were different: the same data set with the same code as before. I am trying to figure out where the difference comes from.
>
> Any thought would be appreciated!
>
> Wu
>
>
>
>
> ----- Original Message -----
> From: Nick Cox <njcoxstata@gmail.com>
> To: "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
> Cc:
> Sent: Monday, May 13, 2013 7:24 PM
> Subject: Re: st: digits difference between stata and mata
>
> 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/
>
>
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index