Hello,
I have a string variable containing a mixture of single and double digits and I would like to use one of Stata's string functions to split them into unique dummy variables. There was a post in which Nick Cox addressed a similar issue involving single digit strings.(https://www.statalist.org/forums/for...ummy-variables). When the string involves a mixture of single digits and double digits, however, the solution provided does not produce the desired outcome. I have tried a number of string functions but the results are not what I expect. How should I go about this? I have posted an example dataset below.
I have a string variable containing a mixture of single and double digits and I would like to use one of Stata's string functions to split them into unique dummy variables. There was a post in which Nick Cox addressed a similar issue involving single digit strings.(https://www.statalist.org/forums/for...ummy-variables). When the string involves a mixture of single digits and double digits, however, the solution provided does not produce the desired outcome. I have tried a number of string functions but the results are not what I expect. How should I go about this? I have posted an example dataset below.
Code:
clear input float hhid str35 iterm float pid 2299 "6" 2 2383 "19" 1 777 "14" 1 1858 "37" 2 72 "19 22" 1 55 "31" 2 114 "6" 1 495 "5 6 29" 1 869 "19" 3 1827 "29 43" 2 784 "5" 2 2107 "4" 1 1081 "4" 1 1001 "19" 3 2132 "19" 2 1198 "3" 2 664 "23" 5 537 "5 6 29" 1 714 "23" 1 1547 "21" 1 472 "5 8 29" 1 452 "19 40" 1 1689 "19" 1 568 "6" 1 359 "19" 1 830 "3" 3 230 "6" 3 1581 "6 29" 1 1799 "19 44" 2 1395 "14 23 27" 7 657 "31" 2 776 "5 29" 2 48 "5 6 19 29" 1 1758 "31" 2 251 "5" 1 1915 "5 8 29" 2 1466 "31" 7 2304 "14" 2 273 "3" 2 774 "29" 2 1090 "6 29" 2 366 "4" 2 68 "19" 1 293 "15" 4 2424 "6 8 29" 1 2441 "3 19" 2 327 "5" 1 976 "19" 1 341 "5" 3 1680 "44" 9 831 "19" 4 1435 "44" 2 2540 "5 6" 3 2198 "5 14 19" 2 466 "3" 2 527 "14" 2 2452 "19" 1 963 "14" 6 1612 "22" 1 1338 "19" 3 1108 "6 7 25" 1 724 "5 8 29 40" 2 1869 "6" 2 1411 "4" 1 75 "6" 3 637 "14" 4 2375 "19" 5 254 "27" 2 1324 "3" 1 363 "6" 1 2122 "22" 6 1118 "3 14" 3 1365 "14" 3 629 "19 40" 1 1791 "6" 2 433 "15" 3 end
Comment