Bookmark and Share

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: loop to create varialbes


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: loop to create varialbes
Date   Thu, 6 Mar 2014 18:57:46 +0000

To be pedantic: Carlos means that a variable _name_ cannot contain periods.

Nick
[email protected]


On 6 March 2014 18:28, Carlos Avellaneda Suárez

> The problem is that a variable in Stata cannot contain periods. Try this:
>
> foreach x of varlist _all {
> gen d_`x'=d.`x'
> }

Snapp, Kevin Michael <[email protected]>:

> I need a loop that will go through my two year panel set and create the first difference for me for each variable.  I don't have a clue about these for each loops.
>>
>> Here is what I tried.
>>
>> foreach x of varlist _all{
>>   generate d.`x' = 'x' - L1.`x'
>>
>> the error msg I get is:
>>
>> d.state invalid name
>> r(198);
>>
>> I would like the new variables to have the same name as the old with a d in front to keep it easy to read.

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index