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   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: Converting a SAS datastep to Stata
Date   Wed, 15 Dec 2010 17:24:40 -0500

Daniel Feenberg <[email protected]>:
If you are wedded to regular Stata commands (as opposed to moving
everything into Mata as I suggested), you can speed up the
calculations by sorting on year and using -in- restrictions instead of
-if- qualifiers.  You collect the relevant observation numbers for
year boundaries once, put them in locals, then tell Stata what
observations each command operates on--goes more than twice as fast in
many cases; see Blasnik's law:
http://www.stata.com/statalist/archive/2007-08/msg00668.html

On Wed, Dec 15, 2010 at 4:33 PM, Daniel Feenberg <[email protected]> wrote:
> Yes, integers only, and the range statement is very clear, however consider
> that there are 18 lines of code for calculating the tax on capital gains
> income in 2003, then 15 lines used only for 2004, etc for 21 years. While I
> personally blame the congress for the frequent tax law changes, that isn't
> relevant for this mailing list.
>
> Here is the SAS code for capital gains under the alternative minimum tax for
> a single year:
>
>  if FLPDYR eq 2003 then do;
>     _amt5pc = min(c24533,min(c24532,min(c62700,c24517)));
<snip> and with non-symmetric treatment of losses]. I think this translates into
> the following Stata code:
>
>     _amt5pc = min(c24533,min(c24532,min(c62700,c24517))) if FLPDYR == 2003
<snip>
> Repeating the if qualifier means repeating a calculation, which is an
> inefficiency, but it also means repeating the code, which is ugly and
> distracting. That is why I asked about the possibility of a block level if
> qualifier. If it doesn't exist, I'll put it in W Gould's suggestion box.
>
> One thing I could do is allow more complex assignment statements, with fewer
> of the intermediate values that are used to clarify purpose and show the
> correspondence to the tax form. That could reduce the number of statements
> by half but is otherwise undesirable.

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