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: RE: st: Converting a SAS datastep to Stata


From   Daniel Feenberg <[email protected]>
To   [email protected]
Subject   Re: RE: st: Converting a SAS datastep to Stata
Date   Thu, 16 Dec 2010 16:17:25 -0500 (EST)


On Thu, 16 Dec 2010, William Gould, StataCorp LP wrote:

I just sent a posting to Statalist concerning Daniel Feenberg's
<[email protected]> SAS-to-Stata issue.

Others have replied, too, and many are saying, "Use Mata!".

I'm a little embarrassed because, concerning Mata, I merely ended my
posting with,

Daniel could use Mata.  That would address both the readability and
efficiency issues.  If I were writing this code for the first time,
that is what I would do, probably.  With Mata, I can go through the
observations one at a time just as SAS does.

Do you mean a "for" loop over observations?

       : for ( 1; st_nobs();1) {
             if FLPDYR[i] == 2003 {
               (calculations...)
             }
          }

(I don't know any Mata, but I am studying Kit Baum's book). Wouldn't that structure be subject to the complaint you voiced about explicitly looping over observations? (following "You would never dream..." in http://www.nber.org/plugins/) If that doesn't apply to Mata (perhaps because Mata is pseudo-compiled) it would be very attractive.


I'm embarrassed because I am the author of the "Mata Matters" column
in the SJ.  I'm supposedly qualified because I'm the author of Mata, too,
but the editors of the SJ may be reconsidering.

So please pretend I too said, "Use Mata!" and added a lot of useful
comments about Mata.  Mata is, in fact, very appropriate for
Daniel's problem.

I didn't push the Mata solution for two reasons:  (1) I pretty much
ignored efficiency issues and (2) I was unsure of how much Mata
Daniel knew.  Assuming efficiency is not Daniel's primary concern,
and assuming time-of-implementation is, I stand behind my Stata solution.



At the moment I am thinking the Mata way would be to separate out the conditionally executed block of code into a separate Mata function, and specify the affected returns as a view before calling that function with the appropriate marksample/touse. This means that much of the code is in traditional Stata, but the conditional blocks are in Mata.

Is that the plan? It looks efficient, but would require a great deal of structural change in the code for conditional blocks and there would be a substantial amount of code for calling each block. Therefore I am inclined to follow your initial suggestion of using local macros judiciously in regular stata code. If the SAS and Stata codes have similar structure, simultaneous maintanance will be simplified.

Thank you for the thoughtful suggestions - I do appreciate all of them and may well change my mind after I start translating.

Daniel Feenberg
NBER

I don't want to be thought of as one-sided.

Cheers,

-- Bill
[email protected]
*
*   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