Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Stata中使用stsplit和strate时,如何获得人口规模而不是人年?_Stata_Frequency_Survival Analysis_Rate - Fatal编程技术网

在Stata中使用stsplit和strate时,如何获得人口规模而不是人年?

在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

在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)) 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
}