Announcement

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

  • Estimating shares for a categorical variable per year and per state

    Hi all,

    I have a categorical variable with three categories (1, 2, 3). I want to find the percentage share of each category per year per state. I can get the results I want if I write:

    Code:
    tab var if year==1977 & state==1
    I was wondering if there is a loop I can make or if there is an easier way to do it because otherwise I will need to make the calculations manually every time. My range is from 1977-2018 for 51 states.

    Thank you in advance for your time.

    Kind regards,
    Alexandros Achilleos

  • #2
    Code:
    bys year : tab state var, row nofreq
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Maarten thank you very much! This is exactly what I wanted. Do you maybe know if it's also able to generate it as a new variable?

      Comment


      • #4
        Code:
        tab var, gen(d)
        bys year state : egen prop1 = mean(d1)
        bys year state : egen prop2 = mean(d2)
        bys year state :  egen prop3 = mean(d3)
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Maarten thank you very much!!

          Comment

          Working...
          X