Hi,
In the following example I am running a twoway crosstab and want to output to excel (using the Stata 13 putexcel command) the -levelsof- values from each variable for the row and column names. I've tried a few different approaches; saving the levelsof values to a local macro, reformatting the matrix itself, but I am relatively new to matrix language and could use some guidance.
And here's what the matrix stars looks like in the console:
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
r1 0 24 16 0 1 6 5 3 0 0
r2 0 0 57 0 8 14 9 1 1 1
r3 2 0 0 0 0 0 0 0 0 0
r4 0 0 2 4 25 12 1 0 0 0
r5 0 0 1 2 31 89 40 2 0 0
r6 0 0 0 0 0 21 53 19 7 0
r7 0 0 0 0 0 1 10 18 12 0
r8 0 0 0 0 0 1 0 7 19 6
r9 0 0 0 0 0 0 0 1 0 2
Thanks for any input!
In the following example I am running a twoway crosstab and want to output to excel (using the Stata 13 putexcel command) the -levelsof- values from each variable for the row and column names. I've tried a few different approaches; saving the levelsof values to a local macro, reformatting the matrix itself, but I am relatively new to matrix language and could use some guidance.
Code:
foreach i of numlist 11 { /*I have 2011 and 2012 data that I merge to perform the crosstab, not relevant for this question*/ local j=`i' + 1 use transitionmatrix_data_20`i', clear merge 1:1 contractnumber using transitionmatrix_data_20`j' tab overall_num_20`i' overall_num_20`j', matrow(freq) matcell(stars) *levelsof overall_num_2012, local(test) /*Works, but not sure how to putexcel into columnames..*/ matrix list stars matrix list freq *Attempting to use the local macro "test" for column names.. putexcel A1=(`test') A2=matrix(freq) B2=matrix(stars) using tabtest4 }
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
r1 0 24 16 0 1 6 5 3 0 0
r2 0 0 57 0 8 14 9 1 1 1
r3 2 0 0 0 0 0 0 0 0 0
r4 0 0 2 4 25 12 1 0 0 0
r5 0 0 1 2 31 89 40 2 0 0
r6 0 0 0 0 0 21 53 19 7 0
r7 0 0 0 0 0 1 10 18 12 0
r8 0 0 0 0 0 1 0 7 19 6
r9 0 0 0 0 0 0 0 1 0 2
Thanks for any input!
Comment