Announcement

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

  • Attempting to export two-way cross-tabulations using tab2xl - having issues in exporting it in the format I need it to be.*


    I am pasting my do-file here using a common data set.

    ***data for question
    webuse auto

    codebook foreign

    tab mpg
    sum mpg

    **generating mpg_categories for example

    generate mpg_categories=.
    replace mpg_categories=1 if mpg>22
    replace mpg_categories=2 if mpg<=22

    label define lab_mpg_cat 1 "Mileage>22" 2 "Mileage<=22"
    label values mpg_categories lab_mpg_cat
    codebook mpg_categories

    ******General problem
    /*
    I have Stata 16.1, I am trying to output cross-tabs into excel sheets in a format which is convenient for direct upload on Tableau for visualisation, using the auto dataset as an example because I cannot use organisational data*/

    ***I am trying to produce an excel sheet for the tabulate command
    tab mpg_categories

    ***I am using the following to output data to an excel file for one way tables and this is working fine (output 1)
    tab2xl mpg_categories using problem_1, row(1) col(1) sheet("sheet 1")

    ******Specific problem
    /*I am also trying to export this exact output (output 2) to an excel file using tab2xl.
    I have been trying for sometime, but I am unable to export the output. I am trying to do this for a lot of variables, so the idea is to loop through the variables and export output 1 and output 2 to excel sheets and then upload them directly to tableau.*/

    **output 2
    tab foreign mpg_categories, column nofreq

    **this is as far as I got
    tab2xl foreign mpg_categories using problem_1, row(1) col(1) sheet("sheet 2")

    **as you can see, I am not getting the percentages, if anyone has any ideas please let me know!



    Last edited by Shourjya Deb; 08 Dec 2020, 07:17. Reason: EDIT: Adding tags
Working...
X