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

From |
"Scott Merryman" <smerryman@kc.rr.com> |

To |
<statalist@hsphsun2.harvard.edu> |

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

Date |
Fri, 25 Apr 2003 21:58:30 -0500 |

----- Original Message ----- From: "Daniel Sabath" <sabathd@u.washington.edu> To: <statalist@hsphsun2.harvard.edu> Sent: Friday, April 25, 2003 7:11 PM Subject: Re: st: Structure for making line by line changes? > On Fri, 25 Apr 2003, Fred Wolfe wrote: > > > At 12:06 PM 4/25/2003 -0700, you wrote: > > >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. > > > > > > Nick's reply is to indicate that you really don't need to loop over > > observations. People coming from SAS very often think that you do. Using > > Stata, in some instances you might need to create an intermediate variable. > > Following up on Nick's reply, we have a problem thinking of cases where you > > really need to do it the way you suggest. Perhaps a specific example would > > clarify your problem for us. > > > > Fred Wolfe > > Thanks Fred and Nick, > > Here's the actual example. Given a data set that looks like > > A1 , A2 , A3 , A4 , A5 , a6 > row1 1 3 . 6 3 4 > row2 3 4 2 . 1 5 > row3 4 5 2 5 6 2 > > I need to pull out the top 3 values and place them into B1, B2 and B3 > > so that > B1 , B2 , B3 > row1 6 4 3 > row2 5 4 3 > row3 6 5 5 > No doubt there are more clever ways to do this, but how about: mvencode _all, mv(-99999) /* or some number smaller than minimum of data set */ rowsort a* ,gen(b1 b2 b3 b4 b5 b6) desc drop b4-b6 mvdecode _all, mv(-99999) You can locate -rowsort- with -findit rowsort- Scott * * 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/

**References**:**Re: st: Structure for making line by line changes?***From:*Daniel Sabath <sabathd@u.washington.edu>

- Prev by Date:
**st: Re: Re: having fun with graph in Stata8** - Next by Date:
**Re: st: random variable transformation** - Previous by thread:
**Re: st: Structure for making line by line changes?** - 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 |