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: Adding a suffix to variables in a local macro
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Adding a suffix to variables in a local macro
Date
Sun, 9 Jun 2013 18:16:11 +0100
You are correct, but there is a simple fix
local commod2 `commod2'98
A more systematic approach is
local commod2
foreach w of local commod {
local commod2 `commod2' `w'98
}
Nick
[email protected]
On 9 June 2013 18:12, G. Anderson <[email protected]> wrote:
> Thanks a lot Nick.
>
> That seems to almost work, but leaves the last variable in the initial list
> commod unchanged:
>
> So I get something like tea98 coffee98 sugar98 wheat
> for commod2.
> Have tried this with a few different variables and always seems to skip the
> last one.
>
> Thanks,
>
> Gareth
>
> On Jun 9 2013, Nick Cox wrote:
>
>> local commod2 : subinstr local commod " " "98 ", all
>>
>> local commod3 : subinstr local commod2 "98" "99", all
>>
>> Such trickery in this kind of context is also documented at
>> http://www.stata.com/support/faqs/data-management/problems-with-reshape/
>> -- not that I expect anyone apart from me to know or remember that.
>>
>> Search for "unab" in that FAQ.
>>
>> Nick
>> [email protected]
>>
>> On 9 June 2013 17:37, G. Anderson <[email protected]> wrote:
>>>
>>>
>>> I have a large list of variables, from which I have created a local
>>> macro:
>>>
>>> local commod tea coffee sugar wheat
>>> I also have variables in my data set, which refer to specific years, so I
>>> have variables tea98, coffee98, sugar98, wheat98 etc
>>>
>>> I would like to create a local macro referring to each year, so:
>>>
>>> local commod98 tea98 coffee98 sugar98 wheat98
>>>
>>> local commod99 tea99 coffee99 sugar99 wheat 99
>>>
>>> etc.
>>>
>>> Is there a way to do this, referring to local commod and adding the the
>>> suffix "98" "99" etc?
>>
>> *
>>
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/faqs/resources/statalist-faq/
>> * http://www.ats.ucla.edu/stat/stata/
>>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/