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

st: Code help


From   [email protected]
To   [email protected]
Subject   st: Code help
Date   Tue, 12 Nov 2002 10:11:54 -0000

	I have a large dta file set up containg survival information for
about 500,000 cancer patients in a ceratin area.  I wish to set up a dofile
which will produce tables of relative survival for certain groups of
patients.  

	In total I want to produce 72 seperate tables for patients split
into groups of sex (males, females, both sexes combined), diagnosis year
(diagnosed between 1981/1985, 1986/1990, 1991/1995) and age at diagnosis
(aged between 14/44, 45/54, 55/64, 65/74, 75/84, 85/99, 15/74, 15/99).  

	Thus the first table I wish to produce will be for males diagnosed
between 1981 and 1985 aged between 14 and 44.
	Thus the second table I wish to produce will be for males diagnosed
between 1981 and 1985 aged between 45 and 54.
	...
	Thus the seventy first table I wish to produce will be for both
sexes combined diagnosed between 1991 and 1995 aged between 15 and 74.
	Thus the seventy second table I wish to produce will be for both
sexes combined diagnosed between 1991 and 1995 aged between 15 and 99.

	I know it seems strange wanting to produce 72 tables all at once but
I will be repeating this process over and over again for different dta files
so a do-file is a must.

	I have the code in place to work through this as detailed below with
one glorious omission.  I am unsure where to include the command:

	use ***********.dta

	The do-file I have set up is below, and help or advice would be most
appreciated.

	Christopher D Fergusson   

local c=1

while `c'<=3 {

	if `c'==1 {
		qui keep if sex==1
	}
	else if `c'==2 {
		qui keep if sex==2
	}
	else if `c'==3 {
		qui drop if sex==3
	}

	local b=1

	while `b'<=3 {
		if `b'==1 {
			qui keep if diagyr>=1981
			qui keep if diagyr<=1985
		}
		else if `b'==2 {
			qui keep if diagyr>=1986
			qui keep if diagyr<=1990
		}
		else if `b'==3 {
			qui keep if diagyr>=1991
			qui keep if diagyr<=1995
		}

		local a=1

		while `a'<=8 {
		
			if `a'==1 {
				qui keep if aadx>=14
				qui keep if aadx<=44
			}
			else if `a'==2 {
				qui keep if aadx>=45
				qui keep if aadx<=54
			}
			else if `a'==3 {
				qui keep if aadx>=55
				qui keep if aadx<=64
			}
			else if `a'==4 {
				qui keep if aadx>=65
				qui keep if aadx<=74
			}
			else if `a'==5 {
				qui keep if aadx>=75
				qui keep if aadx<=84
			}
			else if `a'==6 {
				qui keep if aadx>=85
				qui keep if aadx<=99
			}
			else if `a'==7 {
				qui keep if aadx>=15
				qui keep if aadx<=74
			}
			else if `a'==8 {
				qui keep if aadx>=15
				qui keep if aadx<=99
			}
			
			display "a is `a'; b is `b'; c is `c'"

/*The following 4 lines produce the relative survival tables*/
			
			stset ageexit, failure(status=1) origin(aadx) 
			sts list, at(0 1 2 3 4 5)
			stset ageexit status, time0(aadx) 
			strel2,
br(0[.1]1[.25]3[.5]5[1]10)using(life8196.dta)mergeby(period sex age)group(1)
continue

			local a=`a'+1
			
		}
		
		local b=`b'+1

	}

	
	local c=`c'+1

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



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