Dear Stata community,
I have some oddly formatted data, as in the following example dataset:
I have the myvar variable, and the goal variable is what I need. myvar is currently a string including numbers seperated by ":". The goal variable essentially indicates how many gaps there are in the natural number sequence between the first and last number in the string, plus 1. Hence, "1:2:3:4:" returns 1 and "13:18:23:" returns 3.
My problem is that I do not know how to have Stata compute the goal var for me, when I only have myvar. Could anyone please help me with this?
Thanks,
Patrick
I have some oddly formatted data, as in the following example dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str22 myvar float goal "1:2:3:10:11:12:" 2 "1:2:3:4:" 1 "6:7:15:16:22:23:24:25:" 3 "13:18:23:" 3 end
My problem is that I do not know how to have Stata compute the goal var for me, when I only have myvar. Could anyone please help me with this?
Thanks,
Patrick
Comment