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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: problems with using preserve in looping


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

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/


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