Statalist The Stata Listserver


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

Re: st: RE: RE: manipulating string variables


From   Jean Eid <[email protected]>
To   [email protected]
Subject   Re: st: RE: RE: manipulating string variables
Date   Mon, 31 Jul 2006 12:44:47 -0400

One more question regarding manipulating global macros. Is there a way
to do the following
global  reg1 "reg hours $dem ";
where $dem is defined as

global dem "age sex";

and

global dem1 "age";

now I want to replace $dem with $dem1 in $reg1

All the solutions below do not work since stata attempts to execute the
global macro $dem when calling global macro $reg1.

Any help is greatly appreciated.

Jean



Jean Eid wrote:
Thank you So much for the prompt reply.

Jean
Nick Cox wrote:
To Alex's clear exposition two footnotes can be added.
1. In Stata terminology, these are not variables at all, but (global) macros.
2. In Stata 9, -index()- is documented as -strpos()-.
Nick [email protected]
Alex Ogan

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")
22

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

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

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

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.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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