Announcement

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

  • display in a table only the modalities of a variable by year

    Hi, everyone. I am new to stata, please, I would like the stata command to summarize the series below.
    year avis
    2007 2
    2007 2
    2007 2
    2007 2
    2008 4
    2008 4
    2008 4
    2008 4
    2008 4
    by a table that only takes the value of the variable avis per year without calculating the frequencies.

    year avis
    2007 2
    2008 4

  • #2
    Code:
    duplicates drop

    Comment


    • #3
      duplicates is a command I like but here it's destructive, which may not be what you want.

      groups from the Stata Journal can help without changing the dataset. It's a cross-tabulation mapped to a list result. There is a specific option switch just to show the cross-combinations that occur in some data. It's not limited to two variables.

      For more, know that st0496 is an otherwise unpredictable search term. (In choosing a common word as a command name, I went against StataCorp advice. "groups" is itself a word with many connotations.)

      Code:
      . search st0496, entry
      
      Search of official help files, FAQs, Examples, and Stata Journals
      
      SJ-18-1 st0496_1  . . . . . . . . . . . . . . . . . Software update for groups
              (help groups if installed)  . . . . . . . . . . . . . . . .  N. J. Cox
              Q1/18   SJ 18(1):291
              groups exited with an error message if weights were specified;
              this has been corrected
      
      SJ-17-3 st0496  . . . . .  Speaking Stata: Tables as lists: The groups command
              (help groups if installed)  . . . . . . . . . . . . . . . .  N. J. Cox
              Q3/17   SJ 17(3):760--773
              presents command for listing group frequencies and percents and
              cumulations thereof; for various subsetting and ordering by
              frequencies, percents, and so on; for reordering of columns;
              and for saving tabulated data to new datasets


      Code:
      clear 
      input year avis
      2007 2
      2007 2
      2007 2
      2007 2
      2008 4
      2008 4
      2008 4
      2008 4
      2008 4
      end 
      
      . groups year avis
      
        +-------------------------------+
        | year   avis   Freq.   Percent |
        |-------------------------------|
        | 2007      2       4     44.44 |
        | 2008      4       5     55.56 |
        +-------------------------------+
      
      . 
      . groups year avis, show(none)
      
        +-------------+
        | year   avis |
        |-------------|
        | 2007      2 |
        | 2008      4 |
        +-------------+

      Comment


      • #4
        Thanks to Clyde Schechter and Nick Cox for your answers. Nick Cox's method works well. I'm working on stata 14 and had to install the groups command first. Thank you very much.

        Comment

        Working...
        X