Hello all,
My foreach loop will create 6 tables. For each cell, it will display frequencies and %. I'd like to stack those 6 tables together to create a giant table so I can export to excel sheet.
I was able to create this giant table but only has the frequency info, how can I also add the % info?
Is there any better solution to make this giant table?
How can I export the giant table results to excel sheet?
Thanks a lot for any comments or suggestions. Below is my code (I created categorical variables for trunk, price, mph, and weight just for reproducing the data format of my real dataset) and the giant table I created.
all[12,3]
c1 c2 c3
r1 0 2 6
r2 11 10 23
r1 0 2 0
r2 8 10 2
r1 10 5 7
r2 1 7 22
r1 8 7 2
r2 0 5 0
r1 1 9 27
r2 10 3 2
r1 0 2 0
r2 8 10 2
My foreach loop will create 6 tables. For each cell, it will display frequencies and %. I'd like to stack those 6 tables together to create a giant table so I can export to excel sheet.
I was able to create this giant table but only has the frequency info, how can I also add the % info?
Is there any better solution to make this giant table?
How can I export the giant table results to excel sheet?
Thanks a lot for any comments or suggestions. Below is my code (I created categorical variables for trunk, price, mph, and weight just for reproducing the data format of my real dataset) and the giant table I created.
sysuse auto, clear
gen trunk2=.
replace trunk2=0 if trunk <=10
replace trunk2=1 if trunk > 10 & trunk <=15
replace trunk2=2 if trunk >15 & !missing(trunk)
gen price2=0
replace price2=1 if price <10000
gen mpg2=0
replace mpg2=1 if mpg <20
gen weight2=0
replace weight2=1 if weight <3000
foreach var in price2 mpg2 weight2 {
tab `var' trunk2 if foreign==0, row matcell(dcells`var')
mat list dcells`var'
tab `var' trunk2 if foreign==1, row matcell(fcells`var')
mat list fcells`var'
}
mat all = dcellsprice2 \ fcellsprice2 \ ///
dcellsmpg2 \ fcellsmpg2 \ ///
dcellsweight2 \ fcellsweight2
mat list all
all[12,3]
c1 c2 c3
r1 0 2 6
r2 11 10 23
r1 0 2 0
r2 8 10 2
r1 10 5 7
r2 1 7 22
r1 8 7 2
r2 0 5 0
r1 1 9 27
r2 10 3 2
r1 0 2 0
r2 8 10 2
Comment