Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: scrolling over observations


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: scrolling over observations
Date   Mon, 31 Jan 2005 21:13:17 -0000

Michael Blasnik, Scott Merryman and 
Russell Dimond gave good answers. 

Russell's can be telescoped to 

bysort CoName : gen new = _n == 1 
replace new = sum(new) 

or to 

sort CoName 
gen new = sum(CoName != CoName[_n-1])  

and is equivalent to Scott's 
suggestion, except that -egen- 
will not change the sort order. 

In addition, Dr Clovis asked where (s)he is 
going wrong. 

Basically, Dr Clovis is expecting a 
loop in circumstances where Stata won't 
execute one. Consider the code 

gen new=0
local count =0
bysort CoName: replace new = `count'+1  if CoName[_n] ~= CoName[_n-1]
count = `count'+1




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