在Stata中使用stsplit和strate时,如何获得人口规模而不是人年?
在Stata中使用strate时,如何获取组中的人数而不是人年数? 使用队列数据,我在Stata创建了一个生存数据集,如下所示:在Stata中使用stsplit和strate时,如何获得人口规模而不是人年?,stata,frequency,survival-analysis,rate,Stata,Frequency,Survival Analysis,Rate,在Stata中使用strate时,如何获取组中的人数而不是人年数? 使用队列数据,我在Stata创建了一个生存数据集,如下所示: stset end, id(person) failure(event==1) scale(365.25) enter(time start) origin(time dob) stsplit ageband, at(0 (1) 5) after(time=dob) stsplit year, after(time=mdy(1,1,1960
stset end, id(person) failure(event==1) scale(365.25) enter(time start) origin(time dob)
stsplit ageband, at(0 (1) 5) after(time=dob)
stsplit year, after(time=mdy(1,1,1960)) at(40 (1) 45)
replace year = 1960 + year
strate ageband year sex, per(100000) output("rates.dta", replace)
每个人
出生于dob
,在开始日期进入研究,在结束日期离开。如果人员
在此期间发生事件
(事件==1
),则他们将在事件日期离开
stset
创建生存数据。
stsplit
将数据集分为年龄段(0-5岁)和日历年(2000-2005年)
strate
根据ageband
年份
性别
的每个不同值计算费率,并将汇总数据存储在“rates.dta”中。这些汇总结果显示,对于年龄段
年份
性别
:\u D
事件数和\u Y
人年的每个组合,在计算利率时,这将分别是分子和分母
我想计算一下事件在每组总人数中所占的比例
是否有办法将\u Y
作为该组中的总人数,例如年龄段=0,年份=2000,性别=1
除此之外,我如何获得每个组的人数?我的解决方案:
* ADD before stset to get total number of people in the dataset
egen tag = tag(person)
egen N_total = total(tag)
drop tag
stset end, id(person) failure(event==1) scale(365.25) enter(time start) origin(time dob)
stsplit ageband, at(0 (1) 5) after(time=dob)
stsplit year, after(time=mdy(1,1,1960)) at(40 (1) 45)
replace year = 1960 + year
* ADD for each variable / group that you want to find the number of people in
egen tag = tag(person ageband)
egen N_ageband = total(tag), by(ageband)
drop tag
egen tag = tag(person year)
egen N_year = total(tag), by(year)
drop tag
egen tag = tag(person sex)
egen N_sex = total(tag), by(sex)
drop tag
* KEEP variables of interest
keep person event ageband year sex N_total N_ageband N_year N_sex
collapse (mean) N_total N_ageband N_year N_sex, by(ageband sex year person)
* SAVE
save "proportions.dta", replace
strate ageband year sex, per(100000) output("rates.dta", replace)
然后,对于每个组(总数、年龄段、年份、性别),将rates.dta
文件与比例合并。dta
文件:
foreach var in total ageband year sex {
use "rates.dta", clear
merge m:1 person sex ageband year using "proportions.dta", keep(match) nogen
if `var'==total collapse (sum) _D N_`var'
else collapse (sum) _D N_`var', by(`var')
* do any other processing with the results
save "proportions_by_`var'.dta", replace
}