Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: manipulating string variables

From   "Alex Ogan" <>
To   <>
Subject   st: RE: manipulating string variables
Date   Fri, 21 Jul 2006 10:32:45 -0400

Here are some basic examples:

. clear

. global testglobal "hello world, how are you today"

. display "$testglobal"
hello world, how are you today

. display index("$testglobal","you")

. display index("$testglobal","me")

. global testglobal2 = subinstr("$testglobal","today","tomorrow",.)

. display "$testglobal2"
hello world, how are you tomorrow

Hope this helps,

-----Original Message-----
[] On Behalf Of Jean Eid
Sent: Friday, July 21, 2006 10:22 AM
To: stata
Subject: st: manipulating string variables

I have been trying to do the following with no luck (This is a 
simplification rather than exact procedure needed)

Suppose I declare a global variable
global myglobal "hello world, how are you today"

now what I want to do is the following:
a) see whether the string text today exist in $myglobal
b) replace "today" by "tomorrow"
c) instead of "are" I need to change the "a" to "b" let's say.

I know this does not make sense to you right now but I have all these 
regressions defined as global variables and need to manipulate them.

Can this be done in Stata?

I have checked strmatch and the likes but am not able to work it. I am 
looking for something like grep, sub and the likes in Linux.

If you know how to do this Please provide a workable example.

Thank you for your time


*   For searches and help try:

This message is intended solely for the designated recipient(s). It may contain confidential or proprietary information and may be subject to confidentiality protections. If you are not a designated recipient, you may not review, copy, or distribute this message. If you receive this in error, please notify the sender by reply e-mail and delete this message. 

Arrowstreet Capital, L.P. is an Equal Opportunity Employer. 

*   For searches and help try:

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