Announcement

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

  • tab year, frequency and value at the same time

    Hi all,
    This is Quan.

    Suppose there are some variables: Year, tv01sum, tv02sum, tv03sum... tv24sum.
    and I want the frequency of each variable by year and the corresponding value, so I used the command 1) and 2) :

    1) tab year tv01sum,

    Year | .926594 1.009871 1.080069 1.289587 1.414931 1.501757 1.5826 1.81283 1.84273 | Total
    -----------+---------------------------------------------------------------------------------------------------+----------
    1995 | 0 0 0 0 0 0 0 0 0 | 20
    1996 | 0 0 0 0 0 0 0 0 0 | 21
    1997 | 0 0 0 0 0 0 0 0 0 | 17
    1998 | 0 0 0 0 0 0 0 0 0 | 25
    1999 | 0 0 0 0 0 0 0 0 0 | 28
    2000 | 0 0 0 0 0 0 0 0 0 | 22
    2001 | 0 0 0 0 0 24 0 0 0 | 24
    2002 | 0 0 0 23 0 0 0 0 0 | 23
    2003 | 0 0 20 0 0 0 0 0 0 | 20
    2004 | 19 0 0 0 0 0 0 0 0 | 19
    2005 | 0 0 0 0 0 0 0 0 0 | 35
    2006 | 0 23 0 0 0 0 0 0 0 | 23
    2007 | 0 0 0 0 0 0 0 0 0 | 47
    2008 | 0 0 0 0 0 0 0 0 0 | 53
    2009 | 0 0 0 0 0 0 0 0 0 | 102
    2010 | 0 0 0 0 0 0 49 0 0 | 49
    2011 | 0 0 0 0 0 0 0 56 0 | 56
    2012 | 0 0 0 0 0 0 0 0 0 | 46
    2013 | 0 0 0 0 0 0 0 0 0 | 62
    2014 | 0 0 0 0 0 0 0 0 56 | 56
    2015 | 0 0 0 0 56 0 0 0 0 | 56
    2016 | 0 0 0 0 0 0 0 0 0 | 71
    2017 | 0 0 0 0 0 0 0 0 0 | 78
    2018 | 0 0 0 0 0 0 0 0 0 | 83
    2019 | 0 0 0 0 0 0 0 0 0 | 71
    2020 | 0 0 0 0 0 0 0 0 0 | 62
    2021 | 0 0 0 0 0 0 0 0 0 | 71
    -----------+---------------------------------------------------------------------------------------------------+----------
    Total | 19 23 20 23 56 24 49 56 56 | 1,240


    2) tab tv01sum year,

    tv01sum | 2013 2014 2015 2016 2017 2018 2019 2020 2021 | Total
    -----------+---------------------------------------------------------------------------------------------------+----------
    .926594 | 0 0 0 0 0 0 0 0 0 | 19
    1.009871 | 0 0 0 0 0 0 0 0 0 | 23
    1.080069 | 0 0 0 0 0 0 0 0 0 | 20
    1.289587 | 0 0 0 0 0 0 0 0 0 | 23
    1.414931 | 0 0 56 0 0 0 0 0 0 | 56
    1.501757 | 0 0 0 0 0 0 0 0 0 | 24
    1.5826 | 0 0 0 0 0 0 0 0 0 | 49
    1.81283 | 0 0 0 0 0 0 0 0 0 | 56
    1.84273 | 0 56 0 0 0 0 0 0 0 | 56
    1.85737 | 0 0 0 0 0 0 0 0 0 | 46
    1.864857 | 0 0 0 71 0 0 0 0 0 | 71
    1.936111 | 0 0 0 0 0 0 0 0 0 | 22
    1.942507 | 0 0 0 0 0 0 0 0 0 | 47
    2.116618 | 62 0 0 0 0 0 0 0 0 | 62
    2.796433 | 0 0 0 0 78 0 0 0 0 | 78
    2.999791 | 0 0 0 0 0 83 0 0 0 | 83
    3.612133 | 0 0 0 0 0 0 0 0 0 | 53
    3.698417 | 0 0 0 0 0 0 0 0 0 | 28
    4.084477 | 0 0 0 0 0 0 0 0 0 | 35
    4.128462 | 0 0 0 0 0 0 0 62 0 | 62
    4.363868 | 0 0 0 0 0 0 0 0 0 | 25
    5.180235 | 0 0 0 0 0 0 0 0 0 | 17
    5.229447 | 0 0 0 0 0 0 71 0 0 | 71
    5.270842 | 0 0 0 0 0 0 0 0 0 | 102
    7.562442 | 0 0 0 0 0 0 0 0 0 | 21
    7.731169 | 0 0 0 0 0 0 0 0 71 | 71
    10.82921 | 0 0 0 0 0 0 0 0 0 | 20
    -----------+---------------------------------------------------------------------------------------------------+----------
    Total | 62 56 56 71 78 83 71 62 71 | 1,240


    is it possible just tab year, variable value and frequency at the same time, which looks as follows?

    Year | freq. of tv01sum | value of tv01sum
    -----------+---------------------------------------------------------------------------------------------------+----------
    1995 | 20 .926594
    1996 | 21 1.009871
    1997 | 17 1.501757
    1998 | 25 5.229447
    1999 | 28 10.82921
    2000 | 22 5.229447
    2001 | 24 3.612133

  • #2
    Code:
    tabstat tv01sum, by(year) s(n mean) 
    
    tab year, su(tv01sum) nost

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Code:
      tabstat tv01sum, by(year) s(n mean)
      
      tab year, su(tv01sum) nost
      You even provided two different codes. Thank you so much Mr. Cox

      Comment


      • #4
        Here is another one.


        Code:
        groups year tv01sum
        where groups is explained at https://www.statalist.org/forums/for...updated-on-ssc and is to be downloaded from the Stata Journal website. When I named groups in 2003 I used a common English word, and a side-effect of that is that the groups command can be a little hard to find, but here is the otherwise unpredictable key

        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

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Here is another one.


          Code:
          groups year tv01sum
          where groups is explained at https://www.statalist.org/forums/for...updated-on-ssc and is to be downloaded from the Stata Journal website. When I named groups in 2003 I used a common English word, and a side-effect of that is that the groups command can be a little hard to find, but here is the otherwise unpredictable key

          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
          Thank you very much!
          I have one more question on this subject.

          When I use the "tab" command, is it possible to display the result based on the summary of the mean or frequency... instead of the alphabetical order of the country names?

          Again, thanks you

          Comment


          • #6
            Originally posted by Jane Quan View Post

            Thank you very much!
            I have one more question on this subject.

            When I use the "tab" command, is it possible to display the result based on the summary of the mean or frequency... instead of the alphabetical order of the country names?

            Again, thanks you
            Oh, I think I can make that happen with the "groups" command!

            Comment

            Working...
            X