First, you have to remove internal blanks using the -subinstr()- function
replace Variable1 = subinstr(Variable1," ","",.)
Then, you can generate the new variables exploiting the -substr()- function
gen newvar1 = substr(Variable1, 1,1)
gen newvar2 = substr(Variable1, 2,1)
gen newvar3 = substr(Variable1, 3,1)
HTH,
Federico
On May 3, 2013, at 2:34 PM, André Gyllenram wrote:
> Hello,
>
> I have a variable that looks like this:
>
> Variable1
> 10305
> 20607
> 1 3 9
> 1 4 5
>
> From this variable I want to create three new variables. The first one should be equal to the firs digit, the second should be equal to the third digit and the third should be equal to the third digit in variable1.
>
> I have tried to do this using the command destring and subinstr but i must do something wrong because it does not seem to work.
>
> Does anyone know how to do this?
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
--
Federico Belotti, PhD
Research Fellow
Centre for Economics and International Studies
University of Rome Tor Vergata
tel/fax: +39 06 7259 5627
e-mail: federico.belotti@uniroma2.it
web: http://www.econometrics.it
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/