Dan Sabath
> I am very new to Stata and am having some difficulty wrapping my
brain around Stata's methods of data processing. I would like to be
able to process a dataset line by line rather then all at once. I have
found many references to the fact that "if" statements don't work as
expected and a very good comparison between STATA and SAS which
briefly mentions some of the paradigm shifts.
>
> My question to the group is how would you deal with the line by line
processing issue? I need to change each line based on a calulated
value that is dependant upon data in that line.
>
> The "if" qualifier would seem to solve this for some cases, but not
when a program has to be called or a really complex comparison has to
be done.
>
> I wrote a "program" to calculate the value based on args passed into
it.
> "checkfoo" returns a 1 or 0 depending if one of the arglist matches
the first arg.
> so r(checked) = 1 if `k' or `l' is equal to `j'
> otherwise r(checked) = 0.
>
> /*******vastly simplified**********/
> local j = 1
> gen k = 2
> gen l = 3
>
> while `j' < 6 {
> checkfoo `j' `k' `l' /* r(checked) returned equal to 1 when j = 2
or 3*/
> replace k = 4 if r(checked) == 1
> local j = `j' + 1
> }
> /***********************************/
> I would like it to replace "k" on the 2nd and 3rd time through the
loop but not at any other time.
>
> I would be happy if I could just do
> /* psudocode */
> replace k = 4 if checkfoo `j' `k' `l' /* with checkfoo evaluating
true or false */
>
> Any and all suggestions for helping this classical programmer come
up to speed would be greatly appreciated.
I have the reverse problem, being totally unfamiliar with
SAS.
What do you mean by line? In what sense do you think -if-
won't work?
In general, if changes depend entirely on what is
in each observation, in Stata's sense, you should not need
to loop or to write programs.
Nick
[email protected]
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/