[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Paulo Regis" <pauloregis.ar@googlemail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Local in -if expressions |

Date |
Tue, 18 Mar 2008 19:38:38 +0000 |

Dear Stata users, I am having a problem with local macros. Whenever I need to use the -if command, I cannot include in the expression the local. This is not the first time I had this kind od problem but I did not find a way aroud this time. For example, I have 5 dependent (y1-y5) and independent (x1-x5) variables, a trend (created by the code, and included as a variable named "trend") and I want to check for cointegration of each dependent on each independent variable, considering 3 alternative specifications 1_ No constant, No trend 2_ constant, No trend 3_ constant, trend The programme (which I include at the end of the email) selects the specification with the highest Zobs (this is a simplification, actually, i base the selection on AIC). At the end of the programme, I need to post the Zobs (i.e. sample statistic) together with the Zcrit (i.e. critical value). The critical values are from Mackinnon (1990), testing for cointegration. My problem is at the end of the code. I get the error: constant not found r(111); The three -if with locals in the expression, which I reproduce : if (`cons'=="noconstant") & (`tr'="notrend") { scalar Zcrit== -3.98 } if (`cons'=="constant") & (`tr'="notrend") { scalar Zcrit== -3.86 } if (`cons'=="constant") & (`tr'="trend") { scalar Zcrit== -3.39 } What am I doing wrong? (Please, take in mind my code is much more complicated and I cannot check the Zobs and Zcrit by hand. Also, the if blocks include other commands to perform some complementary checks) Cheers Paulo Regis * COMPLETE PROGRAMME: capture postclose Posting capture drop trend capture drop r postfile Posting DepVar IndepVar Zobs Zcritcons Constant trend using "C:\LongRun_VEC.dta", replace global DepVar "y1 y2 y3 y4 y5" global Var "X1 X2 X3 X4 X5" gen trend=_n tsset trend foreach x of global Var { foreach y of global DepVar { regress `y' `x' predict r, residuals *No Constant and No Trend dfuller r, noconstant scalar Zobs=r(Zt) local cons noconstant local tr notrend *Constant and No Trend dfuller r, scalar Zobs2=r(Zt) if Zobs2<Zobs2{ scalar Zobs=Zobs2 local cons constant local tr notrend } *Constant and Trend dfuller r, trend scalar Zobs2=r(Zt) if Zobs2<Zobs{ scalar Zobs=Zobs2 local cons constant local tr trend } dfuller r, `cons' `tr' if (`cons'=="noconstant") & (`tr'="notrend") { scalar Zcrit== -3.89 } if (`cons'=="constant") & (`tr'="notrend") { scalar Zcrit== -3.86 } if (`cons'=="constant") & (`tr'="trend") { scalar Zcrit== -3.39 } drop r post Posting (`y') (`x') (Zobs) (Zcrit) ("`cons'") ("`tr'") } } * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**st: RE: Local in -if expressions***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: Local in -if expressions***From:*"Austin Nichols" <austinnichols@gmail.com>

- Prev by Date:
**Re: st: How to print -help file- originally and physically?** - Next by Date:
**Re: st: converting Eviews data format to Stata** - Previous by thread:
**st: How to print -help file- originally and physically?** - Next by thread:
**Re: st: Local in -if expressions** - Index(es):

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