Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Export cross tabulation table to excel using stata

    Hello folks, this may be a dumb question, but how can i get a cross tabulation output export to excel? For instance, I have the following output from stata

    Code:
                  |   
             frpl | not at al   somewhat  to a great extent  to a minimal extent  to a moderate extent |     Total
    --------------+-------------------------------------------------------+----------
    less than 10% |         1          4          1          0          4 |        10 
                  |     10.00      40.00      10.00       0.00      40.00 |    100.00 
    --------------+-------------------------------------------------------+----------
           10-24% |         0          7         11          6         15 |        39 
                  |      0.00      17.95      28.21      15.38      38.46 |    100.00 
    --------------+-------------------------------------------------------+----------
           25-39% |         8         18         16          7         29 |        78 
                  |     10.26      23.08      20.51       8.97      37.18 |    100.00 
    --------------+-------------------------------------------------------+----------
           40-59% |         7         55         31         25         73 |       191 
                  |      3.66      28.80      16.23      13.09      38.22 |    100.00 
    --------------+-------------------------------------------------------+----------
           60-79% |        10         53         34         30         59 |       186 
                  |      5.38      28.49      18.28      16.13      31.72 |    100.00 
    --------------+-------------------------------------------------------+----------
      80% or more |         4         56         31         21         64 |       176 
                  |      2.27      31.82      17.61      11.93      36.36 |    100.00 
    --------------+-------------------------------------------------------+----------
            Total |        30        193        124         89        244 |       680 
                  |      4.41      28.38      18.24      13.09      35.88 |    100.00
    I want to export both freq, percent, total into excel with appropriate labels. i know putexcel can do it but can someone tell me how? Thanks!

  • #2
    the syntax I use is
    Code:
    tab frpl oppor1, row
    the label for frpl is called frpl1 and the label for oppor1 is called opporlabel.

    Comment


    • #3
      A user recently posted about "asdoc" as well. I'm not super familiar with it, but this might get you started, at least:

      https://www.statalist.org/forums/for...stata-commands

      just install it (ssc install asdoc) and then add it to the beginning of your command (e.g., "asdoc tab VAR1 VAR2") It will create a word document with a nice table in it.

      Comment


      • #4
        I don't know about putexcel, but you could do it with logout or tabout (all from SSC)

        Code:
        * This is the code that worked for me
        local tab_table "C:\Data\Tables for R&R\Table 1 - Tabstat Table"
        logout, save(`tab_table') excel replace: tabstat `rhsvars' if good_g==1, stats(n mean median p25 p75 min max) col(stats) 
        
        * Replacing it with your command (not tested)
        logout, save(`tab_table') excel replace: tabulate frpl oppor1, row

        For examples of tabout tables visit the official on-line gallery and consult the User Guide (skip down to chapter 3). A similar Tabout user guide is available at ResearchGate (you may need to register to download it). But it has a number of really nice tables / crosstabs of survey data (& the Stata code to create them). Link

        Comment


        • #5
          Hi David, thanks so much for your reply. This works perfectly!

          Comment


          • #6
            Hi, I'm now trying to do the same thing. I would like to export the following cross tabulation to excel:

            Click image for larger version

Name:	Screen Shot 2019-03-22 at 11.08.55.png
Views:	2
Size:	46.5 KB
ID:	1489483


            First off, I'm afraid I can't figure out how to properly export the results of my tabulate command to statalist. Hence the screenshot, for which I apologise. I've posted a separate thread about this impasse here: https://www.statalist.org/forums/for...s-to-statalist

            Second, the code David gave, which worked perfectly for Man Yang, is not working for me.

            This is the code I entered:
            Code:
            local tab_table "/Users/rvgleichen/Dropbox/Work/Papers/Article 3/Data Analysis/Analysis Files/Industry Variable/SIC_skill-profile"
            logout, save ('tab_table') excel replace: tabulate SIC skill_profile
            And this is what the Stata results window returned (again, apologies for the screenshot)
            Click image for larger version

Name:	Screen Shot 2019-03-22 at 11.20.36.png
Views:	1
Size:	25.1 KB
ID:	1489484


            Any suggestions for how to proceed are highly appreciated!

            Many thanks for your time and consideration,
            Rosa

            Comment


            • #7
              Try the tabout function, it works well.

              Comment


              • #8
                Both tabout and logout need to be installed before they can used.
                You can install logout with the following command

                Code:
                ssc install logout

                Comment


                • #9
                  Hello, I once again need to export a cross-tabulation from stata to excel. I'm trying to use the logout command again, because I know that worked previously. I can't find the particular script in which I used it, but that doesn't matter as it's an all new project with new data.

                  And now unfortunately the logout command is not working the way I'd like. I'm trying to export a cross-table of the variables 'naics2017' and 'skill' (weighted). Both variables have 3,156,487 observations. See dataex below:

                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input float(naics2017 skill)
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  0 -1
                  end
                  This is the code with which I am trying to export a weighted cross-tabulation of naics2017 and skill to excel:

                  Code:
                  svyset cluster [pweight = perwt], strata(strata) // not sure if this is actually necessary
                  
                  ssc install logout
                  local tab_table "/Users/rvgleichen/Dropbox/Work/Papers/USGERcomp/USGERcomp_industry-skill-profile"
                  logout, save ('tab_table') excel replace: tabulate naics2017 skill [iweight = perwt], nolab
                  Unfortunately, stata is returning a .xml file, instead of the desired .xls (or .xlsx) file.

                  I'm grateful for any help in clearing this roadblock.

                  Best,
                  Rosa

                  Comment


                  • #10
                    asdocx offers a variety of tools to export tables created from tabulation of categorical variables. The tables can be exported to Word, Excel, LaTeX, or HTML. Here is a few links to explore:

                    tabmany – Table of multiple coded answers
                    mrtab – One- and two-way tables of multiple responses
                    tabcount – tabulates frequencies for up to 7 variables
                    tab3way – Three way table of frequencies and percentages
                    missings – Various utilities for managing missing values
                    tabulate, tab1, tab2
                    pctab – report percentages in cross-tabulations
                    crosstab - Tabulation with weighted means, percentages, etc.
                    Regards
                    --------------------------------------------------
                    Attaullah Shah, PhD.
                    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                    FinTechProfessor.com
                    https://asdocx.com
                    Check out my asdoc program, which sends outputs to MS Word.
                    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                    Comment


                    • #11
                      Originally posted by Attaullah Shah View Post
                      asdocx offers a variety of tools to export tables created from tabulation of categorical variables. The tables can be exported to Word, Excel, LaTeX, or HTML. Here is a few links to explore:

                      tabmany – Table of multiple coded answers
                      mrtab – One- and two-way tables of multiple responses
                      tabcount – tabulates frequencies for up to 7 variables
                      tab3way – Three way table of frequencies and percentages
                      missings – Various utilities for managing missing values
                      tabulate, tab1, tab2
                      pctab – report percentages in cross-tabulations
                      crosstab - Tabulation with weighted means, percentages, etc.
                      Thanks, this is great.

                      Comment

                      Working...
                      X