Statalist The Stata Listserver


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

st: RE: looping over observations


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: looping over observations
Date   Wed, 14 Mar 2007 13:30:47 -0000

Your problem isn't clear, but I would guess that 
this solution is (a) incorrect and (b) unnecessary. 

See 

FAQ     . . . . . . . . . . . . . . . . . . . . .  if command vs. if qualifier
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  J. Wernow
        6/00    I have an if command in my program that only seems
                to evaluate the first observation, what's going on?
                http://www.stata.com/support/faqs/lang/ifqualifier.html

Almost certainly you want 

	<command> if ((husbage1>husbage2) | (husbage11 <husbage2))


Nick 
[email protected] 

emre ekinci
 
> I have 100 observations.
> 
> I want to execute some commands for each observation.here is 
> the basic 
> structure:
> 
> local i=0
> 
> while `i'<=100 {
> local ++i
> 
> if ((husbage1>husbage2) | (husbage11 <husbage2)) {
> 
> stata commands
> }
> 
> else {
> stata commands
> }
> 
> }
> 
> if the logical statment is true for the first observation, it 
> executes all 
> commands within the if statement for other observations as 
> well, although 
> the logical statement is false for some observations.
> what is my mistake here? How can I write a loop that executes 
> some bunch of 
> commands (including if else statement)?

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



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