# Create tables /// export tab results directly to excel

#### Marvin85

##### Member
I generating a descriptive report for my boss ( that is just frequency tables). I tab everything in stata and the copy as a table and paste it excel. This can be a cumbersome task if i have many variables. Specifically, I have a bunch of scale variables:Are you proficient in: (1 to 4 scale)
var1 baseball
var2 football
var3 soccer
var4 volleyball

Instead of copy and pasting each of these variables into excel, is there a way to create a table with only the percentages, that is:

1 2 3 4
var1 % % % %
var2
var3
var4

If this is not possible, can I export my frequency table directly into excel? That is, my results from tab var1 can be directly in excel ? Thank you

#### Marvin85

##### Member
Anyone please!!! This is a very good thing to know.. I use this every day.;... but I am tired of copy a paste to excel...

#### bukharin

##### RoboStataRaptor
Personally I would just use -contract-, calculate the percentages, then -export excel-. You could easily write a small program to do this repeatedly.

You could also look at my -table1- command from SSC, but it's designed with a slightly different purpose and I suspect wouldn't be much help in this case.

#### Marvin85

##### Member
Thank you Bukarin. I really appreciate it. however, I am not to familiar with the command contract. It looks complicated. Can you write a syntax example so I can see how you do it. For the moment, I am just copy and pasting everything. I hope you can help me with this.

#### Marvin85

##### Member
Please I really need help on this. I have to do this for many datasets and it is a lot of copy and paste. Please see the attached database and examples of what I want. I tried to find the solution for this on my own but I could. Basically, I have a series of ordanial scale variables.. 1 to 4 scale. I nee just to tab this escales and past them in excel. Please see tab 2 to see what I need.

I really hope you can help me with this.

#### bukharin

##### RoboStataRaptor
Code:
capture program drop props
program define props
syntax varlist(min=1 max=1)

contract varlist'
egen total=total(_freq)
gen percent=100 * _freq / total
gen variable="varlist'"
keep variable percent varlist'
reshape wide percent, i(variable) j(varlist')
end

* temporary file to keep track of results
tempfile results

ds id, not
foreach var of varlist r(varlist)' {
preserve
props var'
capture append using "results'"
save "results'", replace
restore
}

use "results'", clear`

#### Marvin85

##### Member
Thank you very much Bukharin.... you are the best! I found a nice command that help also. It is tabm check it out... it can tabulate in one table many variables that have the same values....

thanks bro!