Announcement

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

  • Issue with Outputting Two-Way Table of Frequencies in Stata

    Dear Stata users,

    I am currently working with Stata 16.1 and encountering an issue while using the outreg and tab commands to generate a two-way table of frequencies.

    Below is an example of my dataset:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(wv103 gender)
    3 0
    3 1
    3 1
    3 0
    3 0
    3 1
    3 0
    2 0
    3 0
    2 1
    2 0
    3 1
    2 1
    3 0
    3 0
    3 0
    . 1
    3 0
    3 0
    2 0
    5 0
    4 1
    3 1
    3 1
    3 0
    3 0
    4 1
    2 1
    2 1
    3 1
    1 1
    4 0
    2 0
    3 1
    3 0
    end
    label values wv103 wv103
    label def wv103 1 " Totally disagree", modify
    label def wv103 2 "Disagree", modify
    label def wv103 3 "Agree", modify
    label def wv103 4 "Totally agree", modify
    label def wv103 5 "Neither agree nor disagree", modify
    label values gender gender
    label def gender 0 "Female", modify
    label def gender 1 "Male", modify
    After running the specified command
    Code:
    logout, save(Table1) excel replace:tab wv103 gender, ce
    The output in Excel appears to be gibberish, similar to the image attached below:
    Click image for larger version

Name:	17.png
Views:	1
Size:	18.3 KB
ID:	1734826


    I am seeking assistance in achieving a well-formatted table in Excel or Word, resembling the desired format shown in the second picture below:
    Click image for larger version

Name:	18.png
Views:	1
Size:	35.4 KB
ID:	1734827


    If you have any suggestions or insights on how to resolve this issue and obtain a cleaner table output, I would greatly appreciate your guidance.

    Thank you in advance for your time and assistance.

    Best regards,

    Mindy

  • #2
    Code:
    ssc install estout, replace
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(wv103 gender)
    3 0
    3 1
    3 1
    3 0
    3 0
    3 1
    3 0
    2 0
    3 0
    2 1
    2 0
    3 1
    2 1
    3 0
    3 0
    3 0
    . 1
    3 0
    3 0
    2 0
    5 0
    4 1
    3 1
    3 1
    3 0
    3 0
    4 1
    2 1
    2 1
    3 1
    1 1
    4 0
    2 0
    3 1
    3 0
    end
    label values wv103 wv103
    label def wv103 1 " Totally disagree", modify
    label def wv103 2 "Disagree", modify
    label def wv103 3 "Agree", modify
    label def wv103 4 "Totally agree", modify
    label def wv103 5 "Neither agree nor disagree", modify
    label values gender gender
    label def gender 0 "Female", modify
    label def gender 1 "Male", modify
    
    estpost tab wv103 gender
    esttab using myfile.rtf, replace cell(b pct(fmt(2))) unstack noobs ///
    nonumb varwidth(30) collab(none) eqlab(, lhs(`e(rowvar)')) mlab(none)

    Use extension .CSV to output as a comma-separated values file which you can open in Excel.

    Res.:

    Code:
    . esttab, replace cell(b pct(fmt(2))) unstack noobs ///
    > nonumb varwidth(30) collab(none) eqlab(, lhs(`e(rowvar)')) mlab(none)
    
    ---------------------------------------------------------------------
    wv103                                Female         Male        Total
    ---------------------------------------------------------------------
    Totally disagree                          0            1            1
                                           0.00         2.94         2.94
    Disagree                                  4            4            8
                                          11.76        11.76        23.53
    Agree                                    13            8           21
                                          38.24        23.53        61.76
    Totally agree                             1            2            3
                                           2.94         5.88         8.82
    Neither agree nor disagree                1            0            1
                                           2.94         0.00         2.94
    Total                                    19           15           34
                                          55.88        44.12       100.00
    ---------------------------------------------------------------------

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Code:
      ssc install estout, replace
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input double(wv103 gender)
      3 0
      3 1
      3 1
      3 0
      3 0
      3 1
      3 0
      2 0
      3 0
      2 1
      2 0
      3 1
      2 1
      3 0
      3 0
      3 0
      . 1
      3 0
      3 0
      2 0
      5 0
      4 1
      3 1
      3 1
      3 0
      3 0
      4 1
      2 1
      2 1
      3 1
      1 1
      4 0
      2 0
      3 1
      3 0
      end
      label values wv103 wv103
      label def wv103 1 " Totally disagree", modify
      label def wv103 2 "Disagree", modify
      label def wv103 3 "Agree", modify
      label def wv103 4 "Totally agree", modify
      label def wv103 5 "Neither agree nor disagree", modify
      label values gender gender
      label def gender 0 "Female", modify
      label def gender 1 "Male", modify
      
      estpost tab wv103 gender
      esttab using myfile.rtf, replace cell(b pct(fmt(2))) unstack noobs ///
      nonumb varwidth(30) collab(none) eqlab(, lhs(`e(rowvar)')) mlab(none)

      Use extension .CSV to output as a comma-separated values file which you can open in Excel.

      Res.:

      Code:
      . esttab, replace cell(b pct(fmt(2))) unstack noobs ///
      > nonumb varwidth(30) collab(none) eqlab(, lhs(`e(rowvar)')) mlab(none)
      
      ---------------------------------------------------------------------
      wv103 Female Male Total
      ---------------------------------------------------------------------
      Totally disagree 0 1 1
      0.00 2.94 2.94
      Disagree 4 4 8
      11.76 11.76 23.53
      Agree 13 8 21
      38.24 23.53 61.76
      Totally agree 1 2 3
      2.94 5.88 8.82
      Neither agree nor disagree 1 0 1
      2.94 0.00 2.94
      Total 19 15 34
      55.88 44.12 100.00
      ---------------------------------------------------------------------
      Dear Andrew Musau,

      I want to express my gratitude for the commands you provided—they are incredibly helpful! Thank you so much for your assistance.

      Best regards,
      Mindy

      Comment

      Working...
      X