I was wondering whether anyone could help me out with my code.
I used the svy: proportion method to get some results. These I wrote to matrices and then I would like to export them into 2 excel files - one for each dependent variable.
This is where I am stuck, the do file doesn't give me an error message, but it does not produce any excel files.
I'm new to using macros, so I think it's probably to do with that.
Code:
local xtab X Y local depvar X Y local indvars ib1.one ib1.two * Get list of variable names local ivnames "" foreach x in `indvars' { local indvar "`x'" local varname=substr("`indvar'",5,.) local ivnames `ivnames' `varname' } * Total percentage, SE, confidence intervals foreach i in `depvar' { svy: proportion "'i'" matrix result=r(table) local n=e(N) matrix `depvar'=J(1,9,.) matrix colnames `depvar'="Percentage" "SE" "Lower95%" "Upper95%" "Difference" "SE" "Pvalue" "stars" "Base" matrix `depvar'[1,1]=result[1,2]*100 matrix `depvar'[1,2]=result[2,2]*100 matrix `depvar'[1,3]=result[5,2]*100 matrix `depvar'[1,4]=result[6,2]*100 matrix `depvar'[1,9]=`n' } * put into excel putexcel set `xtab'.xlsx, replace putexcel A1=matrix(`depvar'),names local row=10 foreach x in `ivnames' { putexcel A`row'=matrix(`x'),rownames local rows=rowsof(`x') local row=`row'+`rows'+1 }
Many thanks if anyone can spot where I made the mistake!
0 Response to Putexcel with local macro
Post a Comment