Announcement

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

  • How to make frequency table using stata and export to excel

    Hi all, it may be a stupid question but I am having trouble generating frequency table directly from stata and hopefully stata can help me export to excel. The final product I was expecting is something like the following:
    Inactive
    (n=9,728)
    Active
    (n=2,633)
    Total
    (n=12,361)
    Gender
    Female 3,325 0.436 1,221 0.569 4,546 0.465
    Male 4,304 0.564 923 0.431 5,227 0.535
    and I have six more categories just like the Gender shown above. All I need is the frequency and percent for inactive, and active and a total frequency (adding inactive and active) and percent.

    For now I can generate frequency table using the following syntax but this only covers one category (such as gender) and also it cannot give me the total part

    Code:
    tab Gender Status, matcell(freq) matrow(names)
    matrix list freq
    matrix list names
    putexcel A1=("Gender") B1=("Inactive") C1=("Active") using results1, replace
    putexcel A2=matrix(names) B2=matrix(freq) using results1, modify
    Any clues please? Thanks!
    Last edited by Man Yang; 30 Mar 2017, 16:08.

  • #2
    Please share an example data set.
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment


    • #3
      Originally posted by Man Yang View Post
      Any clues please? Thanks!
      The matcell option will output the freq counts to a matrix and you can just perform matrix operations from there to create totals and percentages yourself.

      So in your example with a 2x2 matrix output two binary variables (gender and activity), you can produce a "totals" column like so:

      Code:
      mat pretot=J(2,1,1)
      mat totals=freq*pretot
      mat table=freq,totals
      mat list table
      this generates the 2x1 of the totals, then concatenates to the original freq matrix so you have a nice 2x3 with the frequencies and totals on the third column.

      You can perform similar basic matrix operations to get the percentage of row total in matrices for export into Excel using putexcel

      Comment


      • #4
        Thanks! That works.

        Comment

        Working...
        X