Announcement

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

  • Adding Up Text In Stata

    Hello,

    I am relatively new to Stata and am attempting to add up text into a new variable but unsure of how to go about it. I would like to create a new variable that adds up how many barriers each client experienced. I used this code initially, but it didn't work: egen barrstotal=rowtotal(behavdevelop insurance servicenav inadprevMH famsocsupport other). Please see example of data below:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str30 behavdevelop str25 insurance str26 servicenav str31 inadprevMH str21 famsocsupport str5 other
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          "Service Navigation Support" ""                                ""                      "Other"
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          ""                           ""                                ""                      "Other"
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               ""                          ""                           "Inadequate Previous MH Services" ""                      ""     
    ""                               ""                          ""                           ""                                "Family/Social Support" ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          ""                           ""                                ""                      "Other"
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      ""     
    ""                               ""                          "Service Navigation Support" ""                                "Family/Social Support" ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" "Service Navigation Support" ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          "Service Navigation Support" ""                                ""                      ""     
    ""                               ""                          "Service Navigation Support" ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          ""                           "Inadequate Previous MH Services" ""                      ""     
    ""                               ""                          ""                           "Inadequate Previous MH Services" ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               ""                          "Service Navigation Support" ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          "Service Navigation Support" ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          "Service Navigation Support" ""                                ""                      ""     
    ""                               ""                          ""                           "Inadequate Previous MH Services" ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                "Family/Social Support" ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          "Service Navigation Support" ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          ""                           "Inadequate Previous MH Services" ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          "Service Navigation Support" ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          "Service Navigation Support" ""                                ""                      ""     
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          ""                           "Inadequate Previous MH Services" ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               ""                          ""                           ""                                ""                      "Other"
    ""                               "Health Insurance Barriers" ""                           ""                                "Family/Social Support" ""     
    ""                               "Health Insurance Barriers" ""                           ""                                ""                      ""     
    ""                               "Health Insurance Barriers" ""                           ""                                "Family/Social Support" ""     
    "Behavioral/Developmental Needs" ""                          ""                           ""                                ""                      ""     
    end
    Any help would be greatly appreciated!

    Thank you,

    Vanessa Garcia

  • #2
    You have string variables, so you will want to write a loop

    Code:
    g wanted=0
    foreach var of varlist behavdevelop-other{
        quietly replace wanted= wanted+ !missing(`var')
    }

    Comment


    • #3
      great, thank you!

      Comment

      Working...
      X