Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: problems with using preserve in looping


From   ken first <kenscholar2008@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: problems with using preserve in looping
Date   Fri, 24 May 2013 16:20:51 +0100

thanks...however i am using a common (not gen) that can not combine with by.

On 24 May 2013 16:12, William Buchanan <william@williambuchanan.net> wrote:
> What about:
>
> bys year: g B=A*matrix if inrange(year,1991,2011)
>
>
>
> Sent from my iPhone
>
> On May 24, 2013, at 10:55, ken first <kenscholar2008@gmail.com> wrote:
>
>> Dear stata users,
>>
>> I have two questions here and i hope someone can help.
>>
>> 1. I am wondering if someone knows about this strange thing with the
>> looping command. I used the below. sometimes it works and everything
>> runs smoothly and sometimes i get an error message. Does anyone know
>> what i did wrong here?
>>
>> first i have
>>
>> predict A, e
>>
>> then
>>
>> forvalue year = 1991/2011 {
>> preserve
>> keep if  year==`year'
>> gen B=A*matrix
>> restore
>> }
>>
>> already preserved
>> r(621);
>>
>>
>>
>> 2. I need to use the below as there is a matrix that wont work if i
>> simply use if year==`year', but i would like to keep the results I
>> generated after everything has been restored. does anyone know what to
>> do?
>>
>>
>> first i have
>>
>> predict A, e
>>
>> then
>>
>> forvalue year = 1991/2009 {
>> preserve
>> keep if  year==`year'
>> gen A=B*matrix   * i would like to keep the result here as a separate variable.
>> restore
>> }
>>
>> Many thanks
>>
>> Ken
>> *
>> *   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index