Rufus Peabody <[email protected]>:
I am guessing there are a number of errors in that code, but I can't
see what is causing the error message you got. Try
set trace on
set traced 2
and run again to see where the error is thrown.
Before you do though--check this line
local mark=mark
which sets the value of local mark to the value of the variable mark
in obs#1 in every iteration. Is that what you meant to do?
Also, the condition
if tm_gmid_yr<=tm_gmid_yr+7 & tm_gmid_yr>=tm_gmid_yr-7
is unlikely to be what you wanted, since it is always true.
On Thu, Aug 28, 2008 at 1:55 AM, Rufus Peabody <[email protected]> wrote:
> I ran the following code, but got the error message "too many macros". What
> I'm trying to do is create a macro that includes the regressors to use for
> that specific time through the loop. It includes a different number of
> regressors each time. For each "tm_gmid_yr" I'm looping through, I want
> the regressors to be all lags possible within that year (by week--so L`i'.,
> L`i+7'.,..., where i is based on the remainder when dividing "tm_gmid_yr" by
> 7 ). Anybody have any idea how to get around this problem?
>
> local mark=mark
> forvalues year=2000/2007 {
> forvalues tm_gmid_yr=7/156 {
> foreach v of local ratevars {
> cap gen `v'_norm_pred=.
> cap gen `v'_norm_pred2=.
> tempvar pred1 pred2
> local regressors "lweek_`v'_norm"
> local x=mod(`mark',`tm_gmid_yr')
> local regressors "`"`regressors'
> L`x'.lweek_`v'_norm"'"
> local y=floor(mark/7)
> while(`y'>=1) {
> local num=(7*`y')+`x'
> local regressors "`"`regressors'
> L`num'.lweek_`v'_norm"'"
> local y=`y'-1
> }
> regress nweek_`v'_norm `regressors' if
> tm_gmid_yr<=tm_gmid_yr+7 & tm_gmid_yr>=tm_gmid_yr-7 & year<=`year'
> predict `pred1' if year==`year' &
> tm_gmid_yr==`tm_gmid_yr'
> regress nweek_`v'_norm `regressors' if year<=`year'
> predict `pred2' if year==`year' &
> tm_gmid_yr==`tm_gmid_yr'
> replace `v'_norm_pred=`pred1' if year==`year' &
> tm_gmid_yr==`tm_gmid_yr'
> replace `v'_norm_pred2=`pred2' if year==`year' &
> tm_gmid_yr==`tm_gmid_yr'
> drop `pred1' `pred2'
> }
> }
> }
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/