Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Regular expressions with locals
From
Tirthankar Chakravarty <[email protected]>
To
[email protected]
Subject
Re: st: Regular expressions with locals
Date
Mon, 25 Jun 2012 23:27:02 -0700
Meant, "...logical conditions which generated those dummies using the..."
T
On Mon, Jun 25, 2012 at 11:24 PM, Tirthankar Chakravarty
<[email protected]> wrote:
> I am pretty sure there are easier ways to do what you are trying
> (generating dummies using some kind of -xi- and then retrieving the
> logical conditions which generated those conditions using the
> auto-generated variables names), here is some code that does what you
> want:
>
> *-----------------------------------------------------------
> local dumnames
> forvalues i = 1/10 {
> local dumnames "`dumnames' _Iphstat_`i'"
> }
> di "`dumnames'"
>
> foreach x of local dumnames {
> if regexm("`x'", "^_I([A-Za-z0-9-]+)_([0-9])$") {
> local dumcond`i' "`=regexs(1)'=`=regexs(2)'"
> di "`dumcond`i''"
> }
> }
> *-----------------------------------------------------------
>
> You should be able to make this code much more compact by getting rid
> of the loop.
>
> T
> On Mon, Jun 25, 2012 at 9:33 PM, Anthony Hong <[email protected]> wrote:
>> Hello! I have in a local macro a list of variables such as _Iphstat_1
>> from xi: logistic. I would like to remove the _I from the beginning
>> and the _# from the end and create a new local with simply a string
>> "phstat = 1".
>>
>> How might I go about doing this?
>>
>> I realize this can be done with various string functions, but I'm
>> curious about the regex commands.
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/statalist/faq
>> * http://www.ats.ucla.edu/stat/stata/
>
>
>
> --
> Tirthankar Chakravarty
> [email protected]
> [email protected]
--
Tirthankar Chakravarty
[email protected]
[email protected]
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/