Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: decompose string

From   "Nick Cox" <>
To   <>
Subject   st: RE: decompose string
Date   Mon, 8 Mar 2010 18:06:20 -0000

I'd use names that make it explicit which character is included. 

forval j = 1/9 { 
	gen v1_`j'= substr(v1, `j', 1) 


John Bunge

I have a string variable v1. It contains names, e.g. "James" or "Valentine". I want to decompose v1 into string variables v2, v3, v4, ... that each contains one letter of v1.

The result:

*-----------begin example------------

v1              v2   v3   v4   v5   v6   v7   v8   v9 v10

James         J     a     m     e     s

Valentine   V    a      l      e     n     t       i      n    e

*-----------end example------------

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index