Announcement

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

  • Calculate a percentage for each group of respondent to questionnaire

    Hi everybody,

    I have a questionnaire which is answered by respondent in different country. I need to calculate the percentage ( the number of people who have given specific answer to each question to total number of respondents to that question) and I need to exclude missing values in my calculation.

    . dataex S002 S003 S024 A001 A035 A075

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte S002 int(S003 S024) byte(A001 A035 A075)
    7 20 207 1 0 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 0 1
    7 20 207 2 1 0
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 1
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 0 1
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 2 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 1
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 1 0
    7 20 207 2 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 1 0
    7 20 207 1 1 1
    7 20 207 1 1 1
    7 20 207 1 1 0
    7 20 207 2 1 1
    7 20 207 1 1 0
    7 20 207 1 1 1
    7 20 207 2 0 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 0 0
    7 20 207 1 0 0
    7 20 207 1 1 1
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 3 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 0 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 0 0
    7 20 207 1 1 0
    7 20 207 2 0 0
    7 20 207 1 1 0
    7 20 207 2 1 0
    7 20 207 1 1 0
    7 20 207 2 0 0
    7 20 207 1 1 0
    7 20 207 1 1 0
    7 20 207 1 0 0
    end
    label values S002 S002
    label def S002 7 "2017-2022", modify
    label values S003 S003
    label def S003 20 "Andorra", modify
    label values S024 S024
    label def S024 207 "Andorra (7)", modify
    label values A001 A001
    label def A001 1 "Very important", modify
    label def A001 2 "Rather important", modify
    label def A001 3 "Not very important", modify
    label values A035 A035
    label def A035 0 "Not mentioned", modify
    label def A035 1 "Important", modify
    label values A075 A075
    label def A075 0 "Not mentioned", modify
    label def A075 1 "Belong", modify
    ------------------ copy up to and including the previous line ------------------

    Listed 100 out of 439531 observations
    Use the count() option to list more

    1- Questions are A001 A035 A075

    2- Answers:
    For A001 :
    "Very important", and "Rather important"
    For A035: "Not mentioned"
    For A075: "Belong"

    3-I want to calculate this ratio for each question, in terms of each country ( S003) and the time range (S002)

    For example:

    Country Time range Question1 Question 2 Question3
    Argentine 2017-2022 0.28 0.56 0.96
    Argentine 2010-2014 0.35 0.78 0.94
    Argentine 2005-2009 0.64 0.77 0.86
    Argentine 1999-2004 0.82 0.96 0.96
    Brazil 2017-2022 0.98 0.56 0.96
    Brazil 2010-2014 0.65 0.34 0.28
    Brazil 2005-2009 0.34 0.71 0.94
    Brazil 1999-2004 0.72 0.96 0.37


    Could I ask you help me with the command?
    ​​​​​​​Thanks.



  • #2
    Fimi:
    an idea may be:
    Code:
    . egen wanted_1=pc( A001)
    . tab wanted_1
    
       wanted_1 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       .9090909 |         91       91.00       91.00
       1.818182 |          8        8.00       99.00
       2.727273 |          1        1.00      100.00
    ------------+-----------------------------------
          Total |        100      100.00
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment

    Working...
    X