I wrote the following code to tabulate the mean results for multiple indicators at the same table:
program RESULTS_MEANS
syntax varlist
tempname v se
local k : list sizeof varlist
display as txt %12s "Variable" ///
as txt %10s "Mean" ///
as txt %12s "SE" ///
as txt %12s "N"
forval i = 1/`k' {
local var : word `i' of `varlist'
quietly svy: mean `var'
quietly estat size
quietly estat effects
matrix `v' = e(V)
scalar `se' = sqrt(el(`v',1,1))
display as txt %12s "`var'" ///
" " as res %9.0g _b[`var'] ///
" " as res %9.0g `se' ///
" " as res %9.0g e(N)
}
end
RESULTS_MEANS var1 var2
The results should look like
Variable Mean SE N
var1 0.538 0.015 9396
var2 0.191 0.009 9396
The problem appears when I modify the program to accommodate the "ratio" case to calculate var1/var2
.
Here is the modified code:
program RESULTS_RATIOS
syntax varlist
tempname v se
local k : list sizeof varlist
display as txt %12s "Variable" ///
as txt %10s "Mean" ///
as txt %12s "SE" ///
as txt %12s "N"
forval i = 1/`k' {
local var : word `i' of `varlist'
quietly svy: ratio `var'
quietly estat size
quietly estat effects
matrix `v' = e(V)
scalar `se' = sqrt(el(`v',1,1))
display as txt %12s "`var'" ///
" " as res %9.0g _b[`var'] ///
" " as res %9.0g `se' ///
" " as res %9.0g e(N)
}
end
RESULTS_RATIOS (var1/var2)
Stata gives me this error
/ invalid name
Any suggestions on how to modify the code???