Announcement

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

  • Exporting results to Excel: Distribution table of multiple binary variables

    I have 6 binary variables and want to export to Excel two tables showing the distribution in frequency (number of 1's) and percent (percent of 1's), i.e., the results of
    Code:
    tabm s2_*
    and
    Code:
    tabm s2_*, row nofreq
    . I have set the command directory to my working folder. Then I try to do:

    Code:
    putexcel set figurer, replace
    table, command(tabm s2_*)
    And get the error code: "an expression is required for command tabm because it is an nclass command within option command()"

    Maybe this is because -table- only works on base Stata commands? I know I could do
    Code:
    table () (s2_1)
    for each of my six variables, but then I would get 6 different tables. Maybe a forval-loop and then some sort of command combining the tables would do the trick. Can anyone help here? My data looks something like this:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(s2_1 s2_2 s2_3 s2_4 s2_5 s2_6)
    0 0 0 0 1 0
    0 0 0 1 0 0
    0 0 1 0 0 0
    0 0 1 0 0 0
    1 0 1 1 0 0
    0 0 0 1 0 0
    0 0 0 0 1 0
    0 0 0 0 0 0
    0 0 0 0 0 0
    0 0 1 0 0 0
    0 0 1 0 0 0
    0 0 0 0 0 1
    0 0 0 0 1 0
    0 0 0 0 0 1
    0 0 1 0 0 0
    0 0 1 0 0 0
    0 0 0 0 1 0
    0 0 0 1 0 0
    0 0 0 0 1 0
    0 0 0 0 0 1
    0 0 1 0 0 0
    0 0 0 0 1 0
    0 1 0 0 0 0
    0 0 0 0 1 0
    0 0 1 0 0 0
    0 0 0 1 0 0
    0 0 1 0 0 0
    1 0 0 0 0 0
    1 0 0 0 0 0
    1 0 0 0 0 0
    0 0 1 0 0 0
    end

  • #2
    tabm is fromtab_chi on SSC, as you are asked to explain. The replace option is available to leave the body of the table as a dataset, which can be exported directly. Percent calculations are surely not hard as an extra, either within Stata or within Excel if you prefer.

    Conversely, although confident with tabm I can't comment on how to get it to play with table. My guess is that would be somewhere between awkward and impossible.

    Comment


    • #3
      See also a concurrent thread. https://www.statalist.org/forums/for...bset-of-a-list

      Comment

      Working...
      X