Announcement

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

  • How to Create a One-Way Frequency Table for Multiple Variables in a Single Table?

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long(sex country)
    2 2
    1 1
    2 2
    2 1
    1 2
    2 2
    1 1
    2 2
    2 1
    1 2
    2 2
    2 2
    1 1
    2 2
    1 2
    2 2
    1 1
    2 2
    2 2
    1 2
    end
    label values sex sex
    label def sex 1 "Female", modify
    label def sex 2 "Male", modify
    label values country country
    label def country 1 "Canada", modify
    label def country 2 "USA", modify


    Good evening, I would like to know if it is possible to generate a one-way frequency table for several variables in a single table.

    I would expect to get a result like this:

    Click image for larger version

Name:	Captura de pantalla 2025-09-06 231729.jpg
Views:	1
Size:	21.2 KB
ID:	1781629

    Thank you for your kind help.


  • #2
    Two ways to do it, with and without headers.



    Code:
    tab1 sex country 
    
    foreach v in sex country {
        tab `v'
    }
    See

    Code:
    help tabulate oneway

    Comment


    • #3
      Thank you for your reply, Nick. I had previously tried both commands, but they return multiple separate tables for each variable. What I would like, if possible, is to generate a single table containing information for all the variables.

      Comment


      • #4
        Code:
        dtable  i.(sex country)

        Comment


        • #5
          My code reproduces what you asked for in #1.

          Comment


          • #6
            Thank you, Nick and Clyde, for your responses.
            The solution Clyde recommended was exactly what I was looking for.
            Sorry if in #1 my request wasn’t clear.
            Last edited by Adolfo Aramburu; 07 Sep 2025, 15:22.

            Comment

            Working...
            X