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]

st: problems with using preserve in looping


From   ken first <[email protected]>
To   [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index