Announcement

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

  • Categorizing based on another concatenated string variable

    Hi everyone!
    I don't know if doing this or possible, but I figured I'd ask the Stata geniuses before giving up on this.

    I have a dataset of medical billing records in long format, where each row is a procedure belonging to a visit (so each visit has multiple rows). I've assigned to each procedure a body system (SysProc), and then for each visit, I created a new variable that combines the systems of the different procedure codes (AllSystems). What I now want to do is create a variable that assigns a body system based on the number that is most represented in the AllSystems variable. So for example, if the AllSystems is "; ; ; ; ; 1;, I want that visit to be coded 1. Similarly, if AllSystems is "1; 1 ; 1; 2; 3", I want it to also be coded 1.

    I'm not entirely sure how to do this and would appreciate suggestions!

    Example generated by -dataex-. To install: ssc install dataex
    clear
    input long VisitID str5 ProcedureCode str2 SysProc2 str296 AllSystems
    131 "E41" "1" ". ; . ; 1 ; 1"
    131 "E32" "1" ". ; . ; 1 ; 1"
    132 "E32" "1" ". ; . ; 1 ; 1"
    132 "E41" "1" ". ; . ; 1 ; 1"
    133 "E32" "1" ". ; . ; 1 ; 1"
    133 "E41" "1" ". ; . ; 1 ; 1"
    134 "E32" "1" ". ; . ; 1 ; 1"
    134 "E41" "1" ". ; . ; 1 ; 1"
    135 "E41" "1" ". ; . ; 1 ; 1"
    135 "E32" "1" ". ; . ; 1 ; 1"
    137 "BPA" "5" "5"
    1318 "E529" "1" ". ; 1 ; 1 ; 1 ; 1 ; 1 ; 1"
    1318 "W2P1D" "1" ". ; 1 ; 1 ; 1 ; 1 ; 1 ; 1"
    1318 "COG" "1" ". ; 1 ; 1 ; 1 ; 1 ; 1 ; 1"
    1318 "E09" "1" ". ; 1 ; 1 ; 1 ; 1 ; 1 ; 1"
    1318 "E41" "1" ". ; 1 ; 1 ; 1 ; 1 ; 1 ; 1"
    1318 "E10" "1" ". ; 1 ; 1 ; 1 ; 1 ; 1 ; 1"
    1319 "E09" "1" ". ; 1 ; 1 ; 1 ; 1"
    1319 "W2P1D" "1" ". ; 1 ; 1 ; 1 ; 1"
    1319 "E10" "1" ". ; 1 ; 1 ; 1 ; 1"
    1319 "E41" "1" ". ; 1 ; 1 ; 1 ; 1"
    1320 "E10" "1" ". ; . ; 1 ; 1 ; 1 ; 1"
    1320 "W2P1D" "1" ". ; . ; 1 ; 1 ; 1 ; 1"
    1320 "E09" "1" ". ; . ; 1 ; 1 ; 1 ; 1"
    1320 "E41" "1" ". ; . ; 1 ; 1 ; 1 ; 1"
    1322 "H3E1E" "6" ". ; . ; . ; . ; . ; . ; 6"
    1330 "W2P1D" "1" ". ; . ; . ; 1"
    1332 "E41" "1" ". ; . ; . ; . ; . ; . ; . ; . ; 1"
    1333 "E32" "1" ". ; . ; . ; . ; . ; . ; 1 ; 1 ; 1 ; 1 ; 6"
    1333 "W2P1D" "1" ". ; . ; . ; . ; . ; . ; 1 ; 1 ; 1 ; 1 ; 6"
    1333 "E09" "1" ". ; . ; . ; . ; . ; . ; 1 ; 1 ; 1 ; 1 ; 6"
    1333 "E10" "1" ". ; . ; . ; . ; . ; . ; 1 ; 1 ; 1 ; 1 ; 6"
    1333 "DR11" "6" ". ; . ; . ; . ; . ; . ; 1 ; 1 ; 1 ; 1 ; 6"
    1334 "DR09" "6" ". ; . ; . ; . ; . ; . ; . ; . ; 6"
    1335 "EWPB" "1" "1"
    1336 "E372" "11" ". ; . ; 11"
    1337 "PPSH" "11" ". ; . ; 11"
    1338 "C7D1M" "11" ". ; . ; 11 ; 11"
    1338 "E372" "11" ". ; . ; 11 ; 11"
    1339 "W2P1D" "1" ". ; . ; 1 ; 1 ; 1"
    1339 "E32" "1" ". ; . ; 1 ; 1 ; 1"
    1339 "E09" "1" ". ; . ; 1 ; 1 ; 1"
    1340 "E32" "1" ". ; . ; 1 ; 1 ; 1"
    1340 "E09" "1" ". ; . ; 1 ; 1 ; 1"
    1340 "W2P1D" "1" ". ; . ; 1 ; 1 ; 1"
    1341 "E09" "1" ". ; . ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1341 "E32" "1" ". ; . ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1341 "W2P1D" "1" ". ; . ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1341 "COG" "1" ". ; . ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1341 "E10" "1" ". ; . ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1342 "PPSH" "11" ". ; . ; 11"
    1344 "PPSH" "11" ". ; 11"
    1346 "E529" "1" ". ; . ; 1 ; 1"
    1346 "COG" "1" ". ; . ; 1 ; 1"
    1347 "W2P1D" "1" ". ; 1 ; 1 ; 1 ; 1"
    1347 "E32" "1" ". ; 1 ; 1 ; 1 ; 1"
    1347 "E09" "1" ". ; 1 ; 1 ; 1 ; 1"
    1347 "E10" "1" ". ; 1 ; 1 ; 1 ; 1"
    1348 "E10" "1" ". ; 1 ; 1 ; 1 ; 1"
    1348 "W2P1D" "1" ". ; 1 ; 1 ; 1 ; 1"
    1348 "E09" "1" ". ; 1 ; 1 ; 1 ; 1"
    1348 "E32" "1" ". ; 1 ; 1 ; 1 ; 1"
    1349 "E10" "1" ". ; 1 ; 1 ; 1 ; 1"
    1349 "W2P1D" "1" ". ; 1 ; 1 ; 1 ; 1"
    1349 "E09" "1" ". ; 1 ; 1 ; 1 ; 1"
    1349 "E32" "1" ". ; 1 ; 1 ; 1 ; 1"
    1351 "PPSH" "11" ". ; 11"
    1352 "PPSH" "11" ". ; 11"
    1353 "PPSH" "11" ". ; 11"
    1354 "PPSH" "11" ". ; 11"
    1355 "PPSH" "11" ". ; . ; 11"
    1356 "PPSH" "11" ". ; . ; 11"
    1357 "E301" "11" ". ; . ; . ; 11 ; 11"
    1357 "E311" "11" ". ; . ; . ; 11 ; 11"
    1358 "DR16" "6" ". ; . ; . ; . ; . ; 6"
    1360 "E703" "5" ". ; . ; . ; . ; . ; . ; . ; . ; . ; . ; . ; . ; . ; 5"
    1363 "E32" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1363 "W2P1D" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1363 "E41" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1363 "COG" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1363 "E529" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1364 "E529" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1364 "COG" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1364 "E32" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1364 "W2P1D" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1364 "E41" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1365 "COG" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1365 "W2P1D" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1365 "E32" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1365 "E529" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1365 "E41" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1366 "E41" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1366 "W2P1D" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1366 "E529" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1366 "E32" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1366 "COG" "1" ". ; . ; 1 ; 1 ; 1 ; 1 ; 1"
    1367 "E41" "1" ". ; . ; . ; . ; . ; . ; 1 ; 1 ; 1 ; 1 ; 1 ; 11"
    1367 "E32" "1" ". ; . ; . ; . ; . ; . ; 1 ; 1 ; 1 ; 1 ; 1 ; 11"
    1367 "E529" "1" ". ; . ; . ; . ; . ; . ; 1 ; 1 ; 1 ; 1 ; 1 ; 11"
    1367 "W2P1D" "1" ". ; . ; . ; . ; . ; . ; 1 ; 1 ; 1 ; 1 ; 1 ; 11"
    end
    [/CODE]


  • #2
    The mode() function of egen supports string arguments.

    Comment


    • #3
      Thank you that worked! So simple!

      Comment

      Working...
      X