Hi there,
In order to generate a table that can be used to build a Tableau dashboard, I need to generate a dataset that contains the prevalence (%) and associated CIs and RSEs for a series of variables. For example, the % of mothers in my state who had a pre-term birth in each year (as well as the CIs and RSE for each percentage). After messing around with a bunch of different options, the best (read: least time-consuming) thing I have found to do is to use the collapse command to produce data that I can copy and paste from the data browser into an excel file. The issue I am having is that I recently learned I need to introduce a finite population correction (fpc). As far as I can tell there is no way to introduce this through the collapse command. I am wondering if anyone knows of a way to introduce this correction into the code I am including below, or if there is another way to get what I have described above with the finite population correction. (I unfortunately cannot include data here because it's a confidential dataset)
Thanks in advance!
Hannah
***For variable "variable"***
egen variableyes = total(variable==1), by(certyear)
collapse (sd) sd_variable = variable (firstnm) y= variableyes (count) n= variable (mean) mean_variable= variable (sem) sem_variable = variable, by(certyear)
**CIs**
generate lo_variable = mean_variable - invttail(n-1,0.025)*(sd_variable/sqrt(n))
generate hi_variable = mean_variable + invttail(n-1,0.025)*(sd_variable/sqrt(n))
gen Percent = (mean_variable)*100
gen PercentLCL = lo_variable*100
gen PercentUCL = hi_variable*100
gen PercentRSE = (sem_variable/mean_variable)*100
drop sd_variable
drop lo_variable
drop hi_variable
drop sem_variable
drop mean_variable
In order to generate a table that can be used to build a Tableau dashboard, I need to generate a dataset that contains the prevalence (%) and associated CIs and RSEs for a series of variables. For example, the % of mothers in my state who had a pre-term birth in each year (as well as the CIs and RSE for each percentage). After messing around with a bunch of different options, the best (read: least time-consuming) thing I have found to do is to use the collapse command to produce data that I can copy and paste from the data browser into an excel file. The issue I am having is that I recently learned I need to introduce a finite population correction (fpc). As far as I can tell there is no way to introduce this through the collapse command. I am wondering if anyone knows of a way to introduce this correction into the code I am including below, or if there is another way to get what I have described above with the finite population correction. (I unfortunately cannot include data here because it's a confidential dataset)
Thanks in advance!
Hannah
***For variable "variable"***
egen variableyes = total(variable==1), by(certyear)
collapse (sd) sd_variable = variable (firstnm) y= variableyes (count) n= variable (mean) mean_variable= variable (sem) sem_variable = variable, by(certyear)
**CIs**
generate lo_variable = mean_variable - invttail(n-1,0.025)*(sd_variable/sqrt(n))
generate hi_variable = mean_variable + invttail(n-1,0.025)*(sd_variable/sqrt(n))
gen Percent = (mean_variable)*100
gen PercentLCL = lo_variable*100
gen PercentUCL = hi_variable*100
gen PercentRSE = (sem_variable/mean_variable)*100
drop sd_variable
drop lo_variable
drop hi_variable
drop sem_variable
drop mean_variable
Comment