Announcement

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

  • tabout three ways table

    Dear Statlisters:

    I am trying to do a table that shows the proportions/percentages of ppl who answered yes to a question (q14301_2) on three levels: gender, region (urban vs. rural) and age group.
    I tried to do it using a loop and tabout but was not successful.
    here is an example of my data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(q14301_2 agegrp1 urban) float female
    2  8 1 1
    2 10 1 1
    2  1 1 0
    2  5 1 0
    2  6 1 0
    2  1 1 0
    2  1 1 0
    2  5 1 0
    2  6 1 0
    2  5 1 0
    end
    label values q14301_2 yesno
    label def yesno 2 " No", modify
    label values agegrp1 agegrp1
    label def agegrp1 1 "00_05", modify
    label def agegrp1 5 "20_29", modify
    label def agegrp1 6 "30_39", modify
    label def agegrp1 8 "50_59", modify
    label def agegrp1 10 "=>65", modify
    label values urban Lurban
    label def Lurban 1 "Urban", modify
    Thank you.
    Maye

  • #2
    Unlike Stata's table command, tabout has never been able to produce three-way tables because it is based on Stata's tabulate command. Neither is tabout by-able. But this doesn't mean you can't do three-way tables in tabout. By using loops, and a few macros, it's reasonably straightforward to set up your do fles to produce this kind of output. There's a bit of programming involved, but the skills are worth knowing for general Stata usage, so it's worth taking the time to learn these tricks.
    I quotes from tabout tutorial written by Ian Watson. If you want to produce three-way table, a simple way is to use offical command -table- or user-written command -tab3way- (SSC).

    Comment


    • #3
      You can try tabout (ssc) for this:

      Code:
      webuse auto
      gen price2=price >5000
      gen trunk2= trunk>10
      tabout foreign trunk2 price2 using auto.text

      Comment


      • #4
        You can also try asdoc with table command.
        Code:
        ssc install asdoc
        sysuse auto
        asdoc table grade race married , replace
        Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	34.2 KB
ID:	1489774
        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


        • #5
          Dear Attaullah Shah, how can I get old version of asdoc for Stata 13? I updated new version from SSC, unfortunately asdoc report an error message. Thank you.
          Code:
          which asdoc
          c:\ado\plus\a\asdoc.ado
          *!Version 2.3.3.3: Changes made March 6, 2019: Attaullah Shah; [email protected]
          ...........
          sysuse auto, clear
          egen cprice=cut(price), group(3)
          asdoc table rep78 cprice foreign , replace
          Code:
                         astable():  3001  expected 5 arguments but received 12
                           <istmt>:     -  function returned error

          Comment


          • #6
            Seems your previous version was either not removed or the mata library was still in the memory. Either way, please do the following

            ssc install asdoc, replace
            then close Stata and restart. The lines that you have typed produce expected results.

            Code:
            sysuse auto, clear
            egen cprice=cut(price), group(3)
            asdoc table rep78 cprice foreign , replace
            Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	15.5 KB
ID:	1489820
            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


            • #7
              Thank you Attaullah Shah, my problem in #5 is solved! But another question: when I run -asdoc tabulate- to get two-way tables of summary statistics, Stata report that option summarized() no allowed. Did I ignore setting something?
              Code:
              . sysuse auto, clear
              (1978 Automobile Data)
              
              . asdoc tabulate rep78, summarize(mpg) replace
              option summarize() not allowed
              r(198);
              
              . generate wgtcat = autocode(weight, 4, 1760, 4840)
              
              . asdoc tabulate wgtcat foreign, summarize(mpg) replace
              option summarize() not allowed
              r(198);
              
              . asdoc tabulate wgtcat foreign, summarize(mpg) nofreq replace
              option summarize() not allowed
              r(198);

              Comment


              • #8
                In this version of asdoc, I completely revamped the tabulate command and wrote everything from scratch. The summarize option demanded significant amount of coding which at that time seemed too much for me. So I delayed this part. I shall consider it in next updates or in asdocx.
                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

                Working...
                X