Basically what I need is a separate excel file for each dependent variable, for each year. Named after the "dependent variable _ year".
This is the code I have:
Code:
local depvar X Y local Year "2010" "2011" foreach yr of local Year{ foreach i of local depvar{ svy: proportion `i' if Year==`yr' matrix `i'=r(table) local n=e(N) matrix `i'=J(1,9,.) matrix colnames `i'="Percentage" "SE" "Lower95%" "Upper95%" "Difference" "SE" "Pvalue" "stars" "Base" matrix rownames `i'=`i' matrix `i'[1,1]=result[1,2]*100 matrix `i'[1,2]=result[2,2]*100 matrix `i'[1,3]=result[5,2]*100 matrix `i'[1,4]=result[6,2]*100 matrix `i'[1,9]=`n' putexcel set `i'_`yr'.xlsx, replace local row=10 * write the column names and the row with just the dependent variable putexcel A`row'=matrix(`i'),names } }
I tihnk the mistake is in this line:
Code:
putexcel set `i'_`yr'.xlsx, replace
Does anyone have any ideas?
Oh, and I have to use the putexcel function. Even though using estout and then formatting in Excel later would be easier.
0 Response to putexcel in foreach loop
Post a Comment