I am not sure what you attempt to do but I'd generate the count variable
by the following lines:
1) make sure that date is formated into a "Stata-date" check [U]27.
2)
sort dw date
by dw: gen count=_n if dw=="friday"
I hope this helps anyway
Hans
++++++++++++++++++++++++++++++++
Hans J. Baumgartner
Dept. Public Economics
DIW Berlin
German Institut for Economic Research
phone: +49/30/89789-307
fax : +49/30/89789-114
URL: www.diw.de
www.hansbaumgartner.de
++++++++++++++++++++++++++++++++
[email protected] wrote on 15/04/2005 14:37:54:
> I have data of the form:
>
> date dw incid
> 6/may/00 friday 5
> 7/may/00 saturday 9
> 13/may/00 friday 10
> 14/may/00 saturday 12
>
> 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
> }
>
> which gives:
>
> date dw incid count
> 6/may/00 friday 5 1
> 7/may/00 saturday 9 1
> 13/may/00 friday 10 2
> 14/may/00 saturday 12 2
>
> and then:
>
> collapse (sum) incid (min) date, by(count)
>
> 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?
>
> Regards
>
> Simon Moore
> *
> * 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/
>
*
* 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/