Announcement

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

  • Table command incorrectly calculating % distribution for binary variable

    I am using the following command to export a table into an Excel file, where I want to see the gender distribution by state. Gender is a binary variable (1=female, 0=male):

    collect get: table state gender, stat(freq) stat(percent gender, across(gender))
    putexcel A59 = collect

    I used this command before with a different dataset, and it worked perfectly, but this is what I get when I run the command this time:

    gender
    male female Total
    state
    Banadir
    Frequency 171 186 357
    Percent 0.00 100.00 100.00
    Galmudug
    Frequency 107 103 210
    Percent 0.00 100.00 100.00
    Hirshabelle
    Frequency 115 143 258
    Percent 0.00 100.00 100.00
    Jubaland
    Frequency 122 137 259
    Percent 0.00 100.00 100.00
    South_West
    Frequency 176 181 357
    Percent 0.00 100.00 100.00
    Total
    Frequency 691 750 1,441
    Percent 0.00 100.00 100.00

    I tried to change the format of the binary variable from 0 to 2 for male participants, but the same command gave completely wrong percentages. I also tried to change the format of the gender variable from float to byte, but this did not work either.

    How can I fix this? I searched for similar examples, but I could not find any solutions online for this.

    Thanks a million!

  • #2
    Just as a follow-up, the same issue occurs for other variables - in the example below, you can see that the percentages are incorrect compared to the frequencies:

    Click image for larger version

Name:	Screenshot 2025-07-17 141203.png
Views:	1
Size:	82.6 KB
ID:	1779926

    Comment


    • #3
      I think you want this command:
      Code:
      table state gender, stat(freq) stat(percent, across(gender))
      Best wishes

      Stata 18.0 MP | ORCID | Google Scholar

      Comment


      • #4
        oh I see, thank you for the help

        Comment

        Working...
        X