Announcement

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

  • Tab2xl issues

    Hello everyone,

    I've just come across tab2xl and have been trying to include it in a loop to get a two-way tab for my variables as follows:

    foreach var of global catmyco {
    tab2xl `var' totalmyco using test1, row (1) col (1) missing sheet ("testsheet1")
    }

    However, it's only giving me an excel sheet for the last variable in the global catmyco. The append option is not allowed.
    Does anyone know of a way to get everything in a single sheet?

    p.s: Tabout works, but it just seems like tab2xl would be an easier option.

    foreach var of global catmyco {
    tabout `var' totalmyco using bivar.xls, c(freq col) mi append
    }


    Thank you!

  • #2
    tabxl and tabout are community-contributed commands, and you are asked to explain where they come from (FAQ Advice #12).

    I've never used tabxl and don't even know where it comes from but my guess from your syntax is that you are putting all your tables in the same place. So, tabxl is, very likely, producing them all but you only see the last one produced.


    Comment


    • #3
      Hi Nick!

      Thank you for getting back to me.
      Apologies! I am using Stata15.1 and I think it's a new command described by the help center in stata as below:


      Description

      tab2xl will perform both one-way and two-way tabulation replicas with default formatting and labeling based on the data
      given. This command does not support string variables in two-way form.

      tab2xl was written for the Stata blog. You can view the blog at
      https://blog.stata.com/2018/06/07/ex...-excel-update/

      You are very right that the command is producing the tables, however even when I tried putting the different tables in separate sheets, my code does not work. Perhaps I'm missing something in the code below?

      foreach var of global catmyco {
      tab2xl `var' totalmyco using `"test_`var'.xls"', row(1) col (2) sheet(`"testsheet_`var'")
      }

      foreach var of global catmyco {
      preserve
      insheet using `"test_`var'.xls"', clear nonames
      export excel using `"mytestfile.xlsx"', sheetreplace sheet ("`var'")
      rm `"test_`var'.xls"'
      restore
      }

      import excel using `"mytestfile.xlsx"', describe

      Comment

      Working...
      X