Announcement

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

  • Looking for help with STATA Table layout issues

    Hi everyone!

    I'm looking for some help with table output. Is there any way to tabulate three variables in a certain manner? The data is showing below and I try to sort them as
    Click image for larger version

Name:	1.png
Views:	2
Size:	18.3 KB
ID:	1661459


    If I go with table builder, error shows that " Your layout specification does not uniquely match any items. One or both of the dimensions GAAP and IFRS might help uniquely match items." Is any commend helping with this?
    cap=1 means expensed only,=0 means capitalisers. and gen firm-year=(GAAP==1) firm-year=(IFRS==1)

    For now I can only get format as this:
    Click image for larger version

Name:	2.png
Views:	1
Size:	4.7 KB
ID:	1661460
    How should I trans this to the format I mentioned in the first?

    Many thanks!



    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(cap GAAP IFRS)
    0 0 1
    0 0 1
    0 0 1
    0 0 1
    0 0 1
    0 0 1
    0 0 1
    0 1 0
    0 0 1
    0 0 1
    0 1 0
    0 1 0
    0 0 1
    0 1 0
    0 1 0
    0 0 1
    0 0 1
    0 0 1
    0 1 0
    0 1 0
    0 0 1
    0 1 0
    0 1 0
    0 1 0
    0 0 1
    0 0 1
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 0 1
    0 1 0
    0 1 0
    0 0 1
    0 0 1
    0 0 1
    0 1 0
    0 0 1
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 0 1
    0 1 0
    0 0 1
    0 1 0
    0 0 1
    0 1 0
    0 1 0
    0 0 1
    0 1 0
    0 1 0
    0 0 1
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 0 1
    0 1 0
    0 0 1
    0 1 0
    0 1 0
    0 0 1
    0 1 0
    0 0 1
    0 1 0
    0 1 0
    0 0 1
    0 1 0
    0 1 0
    0 0 1
    0 0 1
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 0 1
    0 0 1
    0 1 0
    0 0 1
    0 0 1
    0 1 0
    0 0 1
    0 1 0
    0 0 1
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 1 0
    0 0 1
    0 1 0
    0 0 1
    end
    ------------------ copy up to and including the previous line ------------------
    Attached Files

  • #2
    You need to start by creating a single "treatment" variable that takes 2 values to distinguish GAAP from IFRS. Something like the following:
    Code:
    generate treatment = 1 if IFRS==1
    replace treatment = 2 if GAAP==1
    label define TREATMENT 1 "Under IFRS" 2 "Under UK GAAP"
    label values treatment TREATMENT
    Then using cap for your rows and treatment for your columns should move you towards the table you seek.

    Added in edit: Here's example code for a table, using your example data.
    Code:
    generate firm_year = 1
    generate treatment = 1 if IFRS==1
    replace treatment = 2 if GAAP==1
    label define TREATMENT 1 "Under IFRS" 2 "Under UK GAAP"
    label values treatment TREATMENT
    label define CAP 0 "Capitalizers" 1 "Expensers"
    label values cap CAP
    table (cap) (treatment result) (), ///
        statistic(sum firm_year) statistic(percent firm_year, across(treatment)) ///
        totals(treatment)
    Code:
    . table (cap) (treatment result) (), ///
    >     statistic(sum firm_year) statistic(percent firm_year, across(treatment)) ///
    >     totals(treatment)
    
    ---------------------------------------------------
                   |              treatment            
                   |     Under IFRS      Under UK GAAP 
                   |  Total   Percent   Total   Percent
    ---------------+-----------------------------------
    cap            |                                   
      Capitalizers |     41     41.00      59     59.00
      Total        |     41     41.00      59     59.00
    ---------------------------------------------------
    Last edited by William Lisowski; 25 Apr 2022, 14:35.

    Comment


    • #3
      Thank you very much!
      Last edited by Cristiana LI; 25 Apr 2022, 18:01.

      Comment


      • #4
        Originally posted by William Lisowski View Post
        You need to start by creating a single "treatment" variable that takes 2 values to distinguish GAAP from IFRS. Something like the following:
        Code:
        generate treatment = 1 if IFRS==1
        replace treatment = 2 if GAAP==1
        label define TREATMENT 1 "Under IFRS" 2 "Under UK GAAP"
        label values treatment TREATMENT
        Then using cap for your rows and treatment for your columns should move you towards the table you seek.

        Added in edit: Here's example code for a table, using your example data.
        Code:
        generate firm_year = 1
        generate treatment = 1 if IFRS==1
        replace treatment = 2 if GAAP==1
        label define TREATMENT 1 "Under IFRS" 2 "Under UK GAAP"
        label values treatment TREATMENT
        label define CAP 0 "Capitalizers" 1 "Expensers"
        label values cap CAP
        table (cap) (treatment result) (), ///
        statistic(sum firm_year) statistic(percent firm_year, across(treatment)) ///
        totals(treatment)
        Code:
        . table (cap) (treatment result) (), ///
        > statistic(sum firm_year) statistic(percent firm_year, across(treatment)) ///
        > totals(treatment)
        
        ---------------------------------------------------
        | treatment
        | Under IFRS Under UK GAAP
        | Total Percent Total Percent
        ---------------+-----------------------------------
        cap |
        Capitalizers | 41 41.00 59 59.00
        Total | 41 41.00 59 59.00
        ---------------------------------------------------
        Thank you very much!

        But there are still having problems like :


        statistic(sum firm_year) statistic(percent firm_year, across(treatment)) ///
        command statistic is unrecognized
        r(199);

        . totals(treatment)
        command totals is unrecognized
        r(199);

        I tried ''ssc install" commend. I don't know what's wrong. Would you mind give some tips.

        Many thanks

        Comment


        • #5
          Your problem is because "///" indicates a command continued onto the following line. You made one of two mistakes.

          If you copied and pasted the entire block of code into Stata's Command window, then it failed because continuation lines are not allowed in the command window. Change
          Code:
          table (cap) (treatment result) (), ///
          statistic(sum firm_year) statistic(percent firm_year, across(treatment)) ///
          totals(treatment)
          into a single line
          Code:
          table (cap) (treatment result) (), statistic(sum firm_year) statistic(percent firm_year, across(treatment)) totals(treatment)
          and try again.

          If instead you copied and pasted the code into Stata's Do-file Editor window, and then selected the lines and ran them one-at-a-time, it failed because the first line is only part of the command. You can correct this by selecting all three lines and running them.

          Let me add: the code I wrote assumes you are running Stata 17. If you are running an earlier version, the command will have to be altered somewhat, although by looking at the output of
          Code:
          help table
          ​​​​​​​on your system, you may be able to figure out what needs to change.

          Comment


          • #6
            Originally posted by William Lisowski View Post
            Your problem is because "///" indicates a command continued onto the following line. You made one of two mistakes.

            If you copied and pasted the entire block of code into Stata's Command window, then it failed because continuation lines are not allowed in the command window. Change
            Code:
            table (cap) (treatment result) (), ///
            statistic(sum firm_year) statistic(percent firm_year, across(treatment)) ///
            totals(treatment)
            into a single line
            Code:
            table (cap) (treatment result) (), statistic(sum firm_year) statistic(percent firm_year, across(treatment)) totals(treatment)
            and try again.

            If instead you copied and pasted the code into Stata's Do-file Editor window, and then selected the lines and ran them one-at-a-time, it failed because the first line is only part of the command. You can correct this by selecting all three lines and running them.

            Let me add: the code I wrote assumes you are running Stata 17. If you are running an earlier version, the command will have to be altered somewhat, although by looking at the output of
            Code:
            help table
            on your system, you may be able to figure out what needs to change.
            It works! Thanks a lot. My version is stata 17.

            Comment

            Working...
            X