Announcement

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

  • how to show mean in each year for categorical data

    Dear researchers,

    I have a panel dataset for the period from 2012-2020. The dependent variable is categorical variable ranked from 1 to 5. I want to show the mean value for each category in each year. I have used the below code but it shows me the percentage, I need to show the mean:

    Code:
    by  year , sort: fre IR_w
    Can you please advise?

    Many thanks in advance.

  • #2
    How about something like this:
    Code:
    sysuse uslifeexp2.dta
    tabstat le, by(year)
    tab year, summarize(le) nostandard nofreq

    Comment


    • #3
      Thanks a lot Alan Neustadtl , but that doesn't show what I need, it's actually showed me the mean for each year, but what I need is the mean for each category in each year??

      Comment


      • #4
        why not just take the code in #2 and, using the last line there, change to a cross-tab by adding the name of your categorical variable after the word "year"? this could also be done for the -tabstat- line by adding the name of your categorical variable after year in the "by()" option

        Comment


        • #5
          Thanks Rich Goldstein , I tried the below code as you mentioned:

          Code:
          tab year (IR_w), summarize ( IR_w)
          But this showed me the overall mean for all categories for each year and the frequency for each category, but this is not what I want, what I want is to show the MEAN for each category for each year???

          Comment


          • #6

            I note that although you keep asking for it the mean "for each category for each year" is unlikely to be what you want really. The mean for category 1 in 2020 is always 1, for category 2 in 2019 is always 2, and so forth.

            I am at a loss to understand what you do want. Please do what we ask (FAQ Advice #12) and give a simple data example and a concrete example of what you want to calculate. Then precise code is likely to be immediate and people won't have to treat this as a guessing game.

            Comment


            • #7
              first, that is not what I suggested; see
              Code:
              help tab2
              second, Nick Cox and I clearly are interpreting your question differently - the answer is, as Nick says, to provide a data example using -dataex- (see the FAQ)

              Comment


              • #8
                Thanks Nick Cox and Rich Goldstein for the clarification. Greatly appreciated.

                Thanks a lot and I very much apologize for any inconvenience caused.

                Comment

                Working...
                X