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: problems with using preserve in looping
From
William Buchanan <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: problems with using preserve in looping
Date
Fri, 24 May 2013 11:12:11 -0400
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 <[email protected]> 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/