Announcement

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

  • Finding the totals of string variables

    Hi everyone,

    I have this dataset that i need to calculate the totals for each program. So, for example, i want to count the number of total number of trainings for the program LDO and lead. The sample applies to the other string variables in the data dataset.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str4 Program str19(Variable1 Variable2) str9 Variable3 str19 Variable4 str9(Variable5 Variable6)
    "lead" ""                    ""                    ""          ""                    ""          ""         
    "lead" "Product Development" ""                    "Training"  ""                    ""          "Training" 
    "lead" "Quality"             "Product Development" ""          "Product Development" ""          ""         
    "lead" "Quality"             ""                    ""          "Product Development" ""          ""         
    "lead" ""                    "Product Development" ""          ""                    ""          ""         
    "LDO"  "Training"            ""                    ""          ""                    "Training"  "Training" 
    "LDO"  "Technical"           "Technical"           "Technical" "Training"            ""          ""         
    "LDO"  ""                    "Training"            "Training"  ""                    ""          ""         
    "LDO"  "Product Development" ""                    ""          ""                    "Technical" "Technical"
    "LDO"  ""                    ""                    ""          ""                    ""          ""         
    "LDO"  ""                    "Technical"           ""          "Technical"           ""          "Technical"
    "LDO"  "Training"            "Technical"           ""          ""                    ""          ""         
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 12 out of 12 observations

    i want it to be presented in this format,
    LDO LEAD
    Product Development
    Technical
    Training

    My plan was to calculate the totals for each column but thats taking too much time. Is there an easy to do this? Please I need help

  • #2
    Code:
    bys Program: gen n =_n
    reshape long Variable, i(Program n)
    drop if V==""
    tab Variable Program
    Resulting in:

    Code:
                        |        Program
               Variable |       LDO       lead |     Total
    --------------------+----------------------+----------
    Product Development |         1          5 |         6 
                Quality |         0          2 |         2 
              Technical |         9          0 |         9 
               Training |         7          2 |         9 
    --------------------+----------------------+----------
                  Total |        17          9 |        26

    Comment

    Working...
    X