Announcement

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

  • Showing values that exist in a value label but are not taken on by a variable in a table/tabulation?

    Hi All,

    I have a variable that represents the answers to the following question on a survey:
    Do you agree or disagree with the following statement: "I love pizza!"
    1. Strongly Agree
    2. Agree
    3. Neither agree nor disagree
    4. Disagree
    5. Strongly Disagree

    In my survey, no respondents selected option 3 ("Neither agree nor disagree"). However, I want to show in my tabulations, that respondents were presented with that option--even though nobody selected it.

    Running tab pizza, I get:
    pizza freq per cum
    1. Strongly Agree 22 22 22
    2. Agree 32 32 56
    4. Disagree 27 27 83
    5. Strongly Disagree 17 17 100
    Total 100 100

    But, I would like to see (note the bolded row):
    pizza freq per cum
    1. Strongly Agree 22 22 22
    2. Agree 32 34 56
    3. Neither agree nor disagree 0 0 56
    4. Disagree 27 27 83
    5. Strongly Disagree 17 17 100
    Total 100 100



    I know that Stata can't know that it's *possible* for the variable pizza to take on value 3 but doesn't, but I'm wondering if it can tell how often the pizza variable takes on each of the values labeled by pizza_lab?



    The following code creates data like mine:
    Code:
    clear 
    set obs 100 
    
    
    generate pizza = floor(runiform(1,6)) 
    recode pizza 3=2 
    
    label define pizza_lab 1 "Strongly Agree" 2 "Agree" 3 "Neither agree nor disagree" 4 "Disagree" 5 "Strongly Disagree"
    label val pizza pizza_lab
    
    numlabel, add force 
    
    tab pizza
    Thanks,
    Daniel

  • #2
    fre from SSC will do this.

    Code:
    input answer freq
    1 22
    2 32
    4 27
    5 17
    end
    label def answer 1 "Strongly agree" 2 "Agree" 3 "Neither agree nor disagree" 4 "Disagree" 5 "Strongly disagree"
    label val answer answer
    
    fre answer [w=freq], includelabeled
    
    
    (frequency weights assumed)
    
    answer
    ----------------------------------------------------------------------------------
                                         |      Freq.    Percent      Valid       Cum.
    -------------------------------------+--------------------------------------------
    Valid   1 Strongly agree             |         22      22.45      22.45      22.45
            2 Agree                      |         32      32.65      32.65      55.10
            3 Neither agree nor disagree |          0       0.00       0.00      55.10
            4 Disagree                   |         27      27.55      27.55      82.65
            5 Strongly disagree          |         17      17.35      17.35     100.00
            Total                        |         98     100.00     100.00          
    ----------------------------------------------------------------------------------
    Last edited by Nick Cox; 15 Jun 2022, 17:00.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      fre from SSC will do this.
      Thank you Mr. Cox, this solution worked for me.

      Comment

      Working...
      X