Announcement

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

  • egen command after creating a table with the tab command

    I have a question about the egen command.

    I have used the tab command to create the following table:

    Click image for larger version

Name:	egen command after tab command.png
Views:	1
Size:	86.7 KB
ID:	1445980
    1. I want to drop all the countries whose total above (i.e. Total col) is less than or equal to 5.
    1. Next, I will use the same tab command and inspect the External Assurance – Yes column. If there are any zeros in this column, I will drop them later.
    I know that there is a egen tag command that can tag based on the Total column above. I have used the following command, but have not been successful. I would be grateful for your help.

    egen tagc = tag(CountryofIncorporation) if total<=5
    total not found
    r(111);

    How can I accomplish steps 1. And 2. above with or without the egen command?

  • #2
    If there are never any missing values of either Country of Incorporation or External Assurance, then your first task is just dropping any country with fewer than 5 observations. The code for that, assuming your country of incorporation variable is called country, would be:

    Code:
    by country, sort: drop if _N <= 5
    To drop those countries where external assurance is never Yes, and assuming that the external assurance variable is called external_assurance and is coded 0 = No, 1 = Yes:

    Code:
    by country: egen some_external_assurance = max(external_assurance)
    drop if !some_external_assurance
    In the future, to simplify matters and avoid having people make assumptions about your data which may not be true, it is best to show example data whenever you ask for help with code. When showing data examples, please use the -dataex- command to do so. If you are running version 15.1 or a fully updated version 14.2, it 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.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Dear Dr. Schechter,

      Thank you very much for your suggestions. I will look up -dataex- asap.

      Thanks!
      Sunita

      Comment


      • #4
        Further, your assumption was correct - I had no missing data and I had coded the external_assurance variable 0=No and 1=Yes. Your suggested Stata commands work beautifully!

        Comment

        Working...
        X