I have code to estimate two groups difference.I want to assign specific year groups instead of sample1 and sample2. For example, let sample1 have years from 2006 to 2012 and sample2 have years from 2017 to 2021. When I write them as local variables,
local sample1 2006 2008 2009 2010 2011 2012
local sample2 2017 2018 2019 2020 2021
local year sample
global sample1 `sample1'
global sample2 `sample2'
I get 'invalid 2007' error in the following code.
How do I calculate the difference between these two groups by looping them in my year variable. I have tried many commands inrange, egen etc. none of them worked and I kept getting different errors. I would appreciate any help.
local sample1 2006 2008 2009 2010 2011 2012
local sample2 2017 2018 2019 2020 2021
local year sample
global sample1 `sample1'
global sample2 `sample2'
I get 'invalid 2007' error in the following code.
How do I calculate the difference between these two groups by looping them in my year variable. I have tried many commands inrange, egen etc. none of them worked and I kept getting different errors. I would appreciate any help.
Code:
foreach var of varlist `indepvars5' { sum `var' [aw=dwt] if `sample1' local `var'`sample1' : di %12.2f r(mean) sum `var' [aw=dwt] if `sample2' local `var'`sample2' : di %12.2f r(mean) local `var'change (`var'`sample1' - `var'`sample2') / `var'`sample2' * 100 di "`var'change" svy: mean `var', over(year) lincom [`var']`sample1'- [`var']`sample2' *mat L = (r(estimate), r(se),r(estimate)/r(se) , 2*ttail(r(df),abs(r(estimate)/r(se))) local x : di %9.0g 2*ttail(r(df),abs(r(estimate)/r(se))) local y: di %12.3f `x' local p`var' "`y'" } local j foreach var of varlist `indepvars5' { local j = `j' + 1 qui sum `var' if `sample2' [aw=dwt] local mean`sample2' : di %12.2f r(mean) qui sum `var' if `sample1' [aw=dwt] local mean`sample1' : di %12.2f r(mean) local meandiff : di %12.1f (`mean`sample1'' - `mean`sample2'') / `mean`sample2'' * 100 svy: mean `var', over(year) lincom [`var']`sample1'- [`var']`sample2' local x : di %9.0g 2*ttail(r(df),abs(r(estimate)/r(se))) local y: di %12.3f `x' local all`var'`j' "`mean`sample2'' & `mean`sample1'' & `meandiff' & p < `y' " di "`all`var'`j''" }
Comment