Re: st: Creating new variables from a STATA panel dataset

tsset t //for using the lag operator. not necessary though since you
can always use _n-1 subscripting
foreach var of varlist *_oldextension {
local countrycode = regexr("`var'", "_.*", "") //chops off the
name of the variable stored in macro var
generate `countrycode'_newextension = (`var' - L.`var') / L.`var'
}
On Wed, Aug 3, 2011 at 1:10 PM, Nick Cox <njcoxstata@gmail.com> wrote:
>
> * cannot be part of a variable name.
>
> Nick
>
> On 3 Aug 2011, at 17:14, Lucio Vinhas de Souza <lvdesouza@yahoo.com> wrote:
>
>> Dear All,
>>
>> Very basic question, for someone that has not used STATA for several years
>> now: I have a panel dataset (adequately tis t and iis id) of several hundred
>> variables, and I want to:
>>
>> a) Generate new variables
>> b) Run a xtbond from those new variables
>>
>> I have been trying to generate new variables which are change rates form
>> the existing ones. The names of the existing variables are all variations
>> from the format “countrycode_extension”. I have been trying to
>>
>> gen “*_extension_new”=((“*_extension”-“*_extension_new”[_n-1])/
>> “*_extension_new”[_n-1])
>>
>> and always get the message
>>
>> *invalid name
>>
>>
>
> *
> * 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/
>
*
* 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/