Announcement

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

  • Calculating share of subgroup

    Hello,
    I'm hoping there is help with a problem I first thought would have an easy solution but now I don't seem to be able to solve.

    I am trying to calculate the share of a subgroup.
    My variable is called stfdem and is scaled from 0-10, 0 meaning people are not at all satisfied with democracy and 10 meaning people are completely satisfied with democracy.
    This question have been repeated throughout the years, so fx 2002, 2004, 2006 etc. I call the variable year.

    I am trying to figure how to see how many percent of the people who was asked the question (so share of total stfdem) who answered on the scale between 5 to 10. So the satisfied ones. And I am trying to see the share for each year.

    Can anybody help me with this?

    Thank you in advance!
    Kind regards,
    Eva

  • #2
    Hi Eva,

    Provide an example of your data using -dataex, and, I'm fairly sure, it will be very easy to provide you with an answer to your question. If your data has a lot of observations, use
    Code:
    sample 100, count
    to provide an example of just 100 observations.

    Comment


    • #3
      Hi Emil,
      I have tried to do as requested, though I wasnt sure how to show example of the 100 observations best.
      See attached pdf.

      and note the variable year is instead called essaar
      Attached Files
      Last edited by Eva Andersen; 20 Apr 2023, 08:50.

      Comment


      • #4
        The command sample may not be the best approach. A better command is dataex.
        Code:
        dataex name stfdem essaar, count(100)
        After running it, check the Stata main screen, and copy the part from "CODE" to "\CODE", paste that directly here. Then users here can use that code to generate their own sample data, and figure out how to help you.

        And as for your data, you can try:

        Code:
        generate satisfy = inrange(stfdem, 5, 10) if !missing(stfdem)
        table essaar, statistic(mean satisfy)
        Those should be the fraction (0-1) of people answering 5-10, by year.

        Comment


        • #5
          Hi Ken,
          thank you for the help, it worked perfectly!
          Sincerly,
          Eva

          Comment

          Working...
          X