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


From   Daniel Feenberg <[email protected]>
To   [email protected]
Subject   Re: st: Converting a SAS datastep to Stata
Date   Tue, 14 Dec 2010 20:16:28 -0500 (EST)


On Tue, 14 Dec 2010, Austin Nichols wrote:

Daniel Feenberg <[email protected]> :
No Mata required; try out this example:

clear
range yr 1993 2010 18
mat x=(2350,2450,2500,2550,2650,2700,2750,2800,2900,3000,3050,3100,3200,3300,3400,3500)
g ex=x[1,yr-1992]
list

This seems very on-point and is my current plan.



But it would be faster to do all the tax calculations in Mata, first
moving the data into Mata.  See also
http://www.stata-journal.com/sjpdf.html?articlenum=pr0017
on translating Fortran into Mata.


Looking at the article, it is oriented towards a person who is weak in Fortran, and strong in Mata, not my situation. The tax code isn't very much like an analytical function, and I would anticipate many instances where I would have to loop over tax returns with conditional statements. I recall that clever APL programmers were often able to convert program control structures into matrix algebra, but I fear that would require time and talent I don't have.

Even in Stata, I am worried a bit about translating block if statements. The SAS block:

   if flpdyr > 1993 & flpdyr < 1998 then do;
       lvalue1 = expr1;
       lvalue2 = expr2;
    end;

could  be translated to:

   gen sample = 1, if flpdyr >1993 & flpdyr < 1998
   gen lvalue1 = expr1, if sample
   gen lvalue2 = expr2, if sample

but that requires redundant and repetive code. There are many blocks and some are 50 to 100 lines long. I am still surprised there isn't any syntax to apply the "if qualifier" to a block of code, and the ability to nest such blocks. Or am I missing something again?

I can see that in Mata there is such syntax, but apparently only if one loops over the observations, which I wish to avoid.

Daniel Feenberg

*
*   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