# Re: st: Analysis of Individual event data

 From Roger Newson To statalist@hsphsun2.harvard.edu Subject Re: st: Analysis of Individual event data Date Fri, 17 Jun 2005 18:28:03 +0100

If Paul creates a dataset with 1 obs per practice and a second dataset with 1 obs per time period, then he could use -joinby- to create a third dataset with 1 obs per combination of practice and time period. He could then use -merge- to merge in his original dataset with 1 obs per combination of practice and time period in which at least one event happened, and then reset the number of events from missing to zero in observations for which _merge==1.

Hope this helps.

Roger

At 17:34 17/06/2005, Paul wrote:

Dear all,

I have a data set that consists of the dates of certain arbitrary events
(hospital appointments), together with various predictors; mainly
date, numeric code for referring doctor (GP) & intervention (pre/post ).
I am interested in whether the intervention is associated with a fall in
the monthly rate of appointments, after adjusting for secular trend
and clustering by GP.

One approach is to collapse the data & perform a Poisson or negative
binomial regression. However, the code needed for this is surprisingly
complex (see below), as I need to ensure that the practices with zero frequencies in
one time period are properly included, and the only way I could see to do this
was to tabulate, save the table as a matrix and then convert it to a data set.

Two questions:
1) Is there a simpler way of collapsing the data without the zero problem
2) Is there a way of analysing the data using it's present structure (or something like it)?

. use "westminster2", clear

. li uniqid aptdate apttype pre_ post_ in 1/5

+----------------------------------------------+
| uniqid aptdate apttype pre_ post_ |
|----------------------------------------------|
1. | 6220 11 Apr 02 first vi 0 1 |
2. | 6159 12 Mar 02 first vi 0 1 |
3. | 6175 21 Mar 02 first vi 0 1 |
4. | 6210 09 Apr 02 first vi 0 1 |
5. | 6165 14 Mar 02 first vi 0 1 |
+----------------------------------------------+

tempname temp

tab refcode prepost if hosp == 1, matcell(temp) matrow(gp_ref_cd)

svmat temp, names(col)
svmat gp_ref_cd ,names(gp_ref_cd)

keep c1 c2 gp_ref_cd
rename gp_ref_cd1 gp_ref_cd
drop if gp_ref_cd >=.

reshape long c, i(gp_ref_cd) j(prepost)
rename c n_appt
gen post = prepost == 2

svyset , psu(gp_ref_cd)
svynbreg n_appt post , irr

*
* 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/
```
--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
Division of Asthma, Allergy and Lung Biology
King's College London

5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: roger.newson@kcl.ac.uk
Website: http://phs.kcl.ac.uk/rogernewson/

Opinions expressed are those of the author, not the institution.

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