Announcement

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

  • Tabulating across variables after using multencode

    Hi Everyone,

    I have a string variable that contains multi-picklist values separated by a semi-colon and I need to count each value's occurrence. After using split to parse the values and using multencode to separate and label all values I became stuck. I think I need to use a loop but not sure how to set that up as I'm a pretty novice user; any help setting this up to count values across variables would be much appreciated.

    My actual data contains many more values so multencode creates 10 new variables, and the picklist contains 33 possible values. I've read the loop in the manual and still can't quite figure it out.

    Here's a pared-down version of something similar:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str256 socialasst
    "Housing; Food"                                        
    "Financial Assistance; Health Supplies"                
    "Financial Assistance; Legal Support; Workplace Issues"
    "Financial Assistance; Rent/Eviction Support"          
    "Cleaning Supplies; Financial Assistance; Food"        
    "Cleaning Supplies; Food; Health Supplies"             
    end
    Code:
    format socialasst %45s
    split socialasst, p("; ")
    
    ssc install multencode
    multencode socialasst1-socialasst3, gen(nsa1-nsa3) label(reason)
    numlabel reason, add



  • #2
    See the tab_chi package on SSC. tabm and tabsplit could be relevant.

    With your variables,


    Code:
    .  tabm nsa?, transpose
    
                          |             variable
                   values |      nsa1       nsa2       nsa3 |     Total
    ----------------------+---------------------------------+----------
     1. Cleaning Supplies |         2          0          0 |         2 
    2. Financial Assistan |         3          1          0 |         4 
                  3. Food |         0          2          1 |         3 
       4. Health Supplies |         0          1          1 |         2 
               5. Housing |         1          0          0 |         1 
         6. Legal Support |         0          1          0 |         1 
    7. Rent/Eviction Supp |         0          1          0 |         1 
      8. Workplace Issues |         0          0          1 |         1 
    ----------------------+---------------------------------+----------
                    Total |         6          6          3 |        15 
    
    
    
    . tabsplit socialasst, p(;)
    
                socialasst |      Freq.     Percent        Cum.
    -----------------------+-----------------------------------
         Cleaning Supplies |          2       13.33       13.33
      Financial Assistance |          4       26.67       40.00
                      Food |          3       20.00       60.00
           Health Supplies |          2       13.33       73.33
                   Housing |          1        6.67       80.00
             Legal Support |          1        6.67       86.67
     Rent/Eviction Support |          1        6.67       93.33
          Workplace Issues |          1        6.67      100.00
    -----------------------+-----------------------------------
                     Total |         15      100.00

    Comment


    • #3
      That's it! And two ways of doing it. Thanks a bunch.

      Comment

      Working...
      X