Announcement

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

  • Adding the number of ids to tabstat table

    Hello Everyone,

    I have a panel data the looks as below and am trying to produce summary statistics table by using the command tabstat as follows:

    tabstat AA BB , statistics( mean sd min p25 median p75 max count ) col(stat)

    I want to add the number of Firms to the table, I understand that count is for observations only. hence, how I can amend my code to add the number of ids too?
    Firm Year AA BB
    X 2010
    X 2011
    X 2012
    Y 2010
    Y 2011
    Y 2012
    Z 2010
    Z 2011
    Z 2012

    Thanks in advance for your support.

    Regards,

    Khaled

  • #2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str2 firm int year byte(aa bb)
    "X " 2010 . .
    "X " 2011 . .
    "X " 2012 . .
    "Y " 2010 . .
    "Y " 2011 . .
    "Y " 2012 . .
    "Z " 2010 . .
    "Z " 2011 . .
    "Z " 2012 . .
    end
    
    by firm, sort: gen distinct_firm = _n == 1
    tabstat aa bb distinct_firm, statistics( mean sd min p25 median p75 max count ) col(stat)
    Now, this may not produce the layout you have in mind. This code adds an extra row to the table for the variable distinct_firm and it gives the number of different firms in the count column of that row. If what you really want is for the AA and BB rows to have the number of distinct firms in their count columns, I do not believe that can be done with -tabstat-. In fact, I can't think of any official Stata command that would do that.

    In the future, when showing data examples, please use the -dataex- command to do so, as I have here. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.


    Comment


    • #3
      Many Thanks Mr. Clyde for your support and your clarifying how I should present my posts here I will consider it in my future posts.

      Comment

      Working...
      X