Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Split a variable that has no markers

From   "Julia A. Gamas" <[email protected]>
To   <[email protected]>
Subject   st: Re: Split a variable that has no markers
Date   Thu, 14 Oct 2004 15:18:51 -0400

Dear all,
I guess I fixed my own problem.  I discovered generate
newvar=substr(Original,1,1) -which gives me either 9 or 1, then replace
newvar=(Original,1,2) if newvar==1 to get 15 instead of 1.  From then on I
can do a similar procedure to extract the rest of the subvariables.
Thanks anyway.

----- Original Message ----- 
From: "Julia A. Gamas" <[email protected]>
To: <[email protected]>
Sent: Thursday, October 14, 2004 3:03 PM
Subject: Split a variable that has no markers

> Dear all,
> I have an alfanumeric (string variable) such as 9002346-A or 15120657-4.
> need to split this up into groups of smaller digits as follows:
> Original            variable 1          variable 2          variable 3
> variable 4
> 9002346-A        9                        002                   346
> A
> 15120657-4      15                       120                   657
> 4
> The split option seems to only allow me to do this if there are spaces (or
> other markers, such as commas) within that variable, ie. 9 002 346-A or
> 9,002,346-A, which is not my case).
> I can't find an option within "strfun" which may help unless I've
> misunderstood the instructions for "char(n)" and "index".
> Also, note that 9 and 15 are different in size, adding a bit of
> to the issue.
> What I want to do can be done in excel (for smaller files) using
> "left(variable location, number of characters)" and "right" functions.
> anybody know if Stata has functions akin to "left" and "right" from excel?
> I can't seem to find any on the online help or stata archives.
> Thank you for any help you can give me.
> Sincerely,
> Julia A. Gamas

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index