dw is day of week and incid is the number of violent incidents recorded
in police stats.
I wanted to collapse by weekend (here assuming a weekend is a Friday and
Saturday) and therefore added in the following id (count):
gen count = 0
local cntr = 1
forval i = 1(2)`=_N' {
qui replace count = `cntr' in `i'
local cntr = `cntr' + 1
}
local cntr = 1
forval i = 2(2)`=_N' {
qui replace count = `cntr' in `i'
local cntr = `cntr' + 1
}
I have two questions. First, I am certain I have seen a more elegant
way of creating the count id posted on Statalist but searching has not
revealed anything. Is there one?
More importantly, if, for some reason, there is a missing saturday in
the data (there isn't at the moment but it is a growing dataset) the
collapse ..., by(count) will not work. Is there an easier way of
numbering successive weekends in Stata?