[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Daniel Sabath <sabathd@u.washington.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Structure for making line by line changes? |

Date |
Fri, 25 Apr 2003 12:06:06 -0700 (PDT) |

Hello, 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. Many thanks, Dan Sabath * * 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/

**Follow-Ups**:**Re: st: Structure for making line by line changes?***From:*David Kantor <dkantor@jhu.edu>

**Re: st: Structure for making line by line changes?***From:*Fred Wolfe <fwolfe@arthritis-research.org>

**Re: st: Structure for making line by line changes?***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: Help with sample size.** - Next by Date:
**Re: st: Structure for making line by line changes?** - Previous by thread:
**st: Help with sample size.** - Next by thread:
**Re: st: Structure for making line by line changes?** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |