Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Carlos Avellaneda Suárez <carlos.avellaneda8@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: loop to create varialbes |
Date | Thu, 6 Mar 2014 13:28:35 -0500 |
The problem is that a variable in Stata cannot contain periods. Try this: foreach x of varlist _all { gen d_`x'=d.`x' } Hope this helps. Carlos 2014-03-06 13:11 GMT-05:00 Snapp, Kevin Michael <ksnapp@iupui.edu>: > Hello > > 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. > > Any help is appreciated. > Regards > Kevin Snapp > IUPUI Economics > ksnapp@iupui.edu > 317 274 5960 > > > * > * 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/