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: Modifying the content of a macro
From
"Nick Cox" <[email protected]>
To
<[email protected]>
Subject
RE: st: Modifying the content of a macro
Date
Wed, 28 Jul 2010 20:53:46 +0100
Jeph's alternative will work fine for your example. If you have very
long varlists, it will bite you by truncating the varlist.
Nick
[email protected]
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Thomas
Speidel
Sent: 28 July 2010 20:48
To: [email protected]
Subject: Re: st: Modifying the content of a macro
Thanks Nick and Jeph. That's exatly what I needed.
Quoting Jeph Herrin <[email protected]> Wed 28 Jul 13:26:41 2010:
> The -list- directive is not working because you substracting
> a string rather than a macro. You can either store "length" in
> a separate macro and then substract that in your statement #2, or
> instead try
>
> local nolength = subinstr("`main'","length","",.)
>
> hth,
> Jeph
>
> On 7/28/2010 3:11 PM, Thomas Speidel wrote:
>> I am writing a loop to cycle through a number of models. For example,
>>
>> . sysuse auto
>> (1978 Automobile Data)
>>
>> . local main mpg price weight
>>
>> . local adjust length gear_ratio turn
>>
>> . foreach c of local main {
>> 2. local nolength: list adjust - "length"
>> 3. logistic foreign `c' `adjust' if "`c'" != "weight"
>> 4. logistic foreign `c' `nolength' if "`c'" == "weight"
>> 5. }
>>
>> Which fails on the second model. How do I modify `adjust' so that the
>> string "length" is removed from its content and applied to the second
>> set of models? In a less automated fashion, I want:
>>
>> . logistic foreign mpg length gear_ratio turn
>> . logistic foreign price length gear_ratio turn
>> . logistic foreign weight gear_ratio turn
>>
>> Preferrably, in this order. Creating another macro without "length"
is
>> not ideal, because I am dealing with a much larger set of covariates.
>> Thanks.
*
* 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/