Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Looping a poisson regression analysis for levelsof a variable


From   Tim Evans <Tim.Evans@wmciu.nhs.uk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Looping a poisson regression analysis for levelsof a variable
Date   Fri, 12 Oct 2012 09:35:10 +0100

Dear all,

I am running a Poisson regression on counts of surgery between two periods (Stata 11.2), however what I have is more than two periods in my data. Want I want to do is work out a loop that keeps the base period, but then cycles through the other periods. In this I have realized that my variable needs to be coded 0,1 or 1,2 etc, but my periods are 0,1,2,3,4. I cant 'keep' periods 0 and 2 as this returns incorrect IRRs.

My data are set up as follows


age     period  st      pyears
1       0       1266    1002323
2       0       3230    1687257
3       0       1251    614507
1       1       1553    1061158
2       1       4072    1665670
3       1       1517    658308
1       2       1536    1033397
2       2       4648    1739356
3       2       1700    671664
1       3       1562    1065275
2       3       5452    1799757
3       3       1770    649461
1       4       1901    1189778
2       4       6311    1900265
3       4       1765    651825

The code I have tried and failed with is this (it fails to restore the data so that I can keep period 0 and 2, period 0 and 3 and so on) At the finish I would like to age for each age group, IRR for period 1 v 0, period 2 v 0, period 3 v 0 and period 4 v 0:

levelsof period, local(levels)
levelsof age, local(age)
preserve
foreach l of local levels {
foreach a of local age {
keep if period==0 | period==`l'
tab period
replace period = 1 if period==`l'
cap nois: poisson st period if age==`a' & inlist(period, 0,`l'), exposure(pyears) irr
}
}
restore



Best wishes

Tim

_DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index