Announcement

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

  • Mutilple variable score

    Dear community,

    I would like to build a graph in order to display the knowledege about a specfic topic. The KAP Survey sample is about 150 subjects big and they respond to several questions on a questionnaire form.

    All variables are Type str9 and Format %9s.
    I would like to build a "scoring system" following these rules:
    if subject "checked" one Variable, then score = "1"
    if subject "checked" two Variables, then score = "2"
    etc...
    if subejct "checked" more than X variables, then score = "X+"

    Below the output of variable 1

    tab Variable 1

    Variable 1 | Freq. Percent Cum.
    ------------+-----------------------------------
    Checked | 126 84.00 84.00
    Unchecked | 24 16.00 100.00
    ------------+-----------------------------------
    Total | 150 100.00



    I guess I will have to generate this "scoring variable" and then with the code "graph bar (count), by (scoring variable) asyvars blabel (bar)" generate the graph.

    Thank you in advance for your help

    Kind regards

    Max



  • #2
    If I understand this correctly, you want something like this

    Code:
    gen count_checked = 0 
    
    foreach v of var answer* { 
           replace count_checked = count_checked + (`v'  == "Checked") 
    } 
    
    histogram count_checked, discrete xtitle(Number of questions checked)
    The result of graph bar is going to look odd if you have say values of 1, 2, 3, 4, 5 and 9.

    As you can't have a variable named Variable 1, you must have some other names. Concrete examples of your data almost always are much more help than trying to impart abstraction. See also https://www.statalist.org/forums/help#stata on giving data examples.


    Comment


    • #3
      Dear Nick,

      thanks for your response. Sorry for not being concrete I will attach here a screenshot of my variables.
      Click image for larger version

Name:	Screenshot 2022-12-06 135159.jpg
Views:	2
Size:	26.6 KB
ID:	1692240
      Let's take a look at v35 to v44. When using "tab" on any of these variables I will get a table similar to the one mentionned above (checked - unchecked) .
      So I would like to show how many subjects "checked" just one variable (say v35) or only two variables (example: v37 and v45) or more than "X" variables.
      Like you said the first step would be

      Code:
      gen count_checked = 0
      it's the second part I am not sure of. How can I say " replace count_checked = 1 if only one of these variables was checked and count_checked = 2 if two were checked and so on?


      for the last part I did like you said and added a little bit of code:
      Code:
      label def count_check  0 "none checked" 1 "one checked" 2 " two checked" ... "more than X checked"
      
      label val count_checked count_checked 
        histogram count_checked, discrete xtitle(Number of questions checked)
      Thanks again
      Attached Files

      Comment


      • #4
        Code:
        gen count_checked = 0  
        
        foreach v of var v35-v44 {        
             replace count_checked = count_checked + (`v'  == "Checked")  
        }
        You loop over the variables one by one and add 1 if Checked and 0 if not. That is a lot easier than trying replace with 2 if there are 2, and so forth. You still have to count that way.

        We aren't keen on screenshots. See again the link in #2. If your data are confidential or sensitive, that's explained too: use fake data instead that are realistic about your problem.

        See also https://www.stata.com/support/faqs/d...rue-and-false/ on the trickery behind adding 1 or 0.

        I have no idea what is X. I see no reason to degrade these counts in what you've said.
        Last edited by Nick Cox; 06 Dec 2022, 09:57.

        Comment

        Working...
        X