# Re: st: optimal lag order in dynamic panel - feed into levinllin

 From "Majah Ravago" To statalist@hsphsun2.harvard.edu Subject Re: st: optimal lag order in dynamic panel - feed into levinllin Date Fri, 23 Nov 2007 22:06:39 -1000

i also tried Nick's suggestion to Dev Vencappa.

foreach k of varlist netprem disclm elr solv {
preserve
keep if variable == "`k'"
local lags
forvalues x = 1/19 {
sum lagrawnotrend if comcode == `x', mean
local lags "`lags' `r(mean)'"
}
levinlin `k', lags(`lags')
restore
}

here's i modifiefd the above to fit in my data
74 is my province i; time is just 7 years

foreach k of varlist  lnpcexp lnpcinc {
preserve
keep if variable == "`k'"
local lags
forvalues x = 1/74 {
sum lagrawnotrend if comcode == `x', mean
local lags "`lags' `r(mean)'"
}
levinlin `k', lags(`lags')
restore
}

but i got the "variable not found.' If somebody can tell me what i am
doing wrong pls. Would appreciate any help.

THanks!!!

On Nov 23, 2007 8:02 PM, Majah Ravago <rmajah@gmail.com> wrote:
> Dear Scott and Sean,
>
> Thank you very much for posting this codes. THis is what i need!
> I just have a few questions 'coz it returns an error to my data.
> i'm a beginner in dynamic panel analysis. i need the optimal lag to
>
> my data is i=77 and T=7 (panel survey of every three  years)
>
> I was trying to adapt the codes below. Why does it only use 12
> countries in the panel?
> I tried removing this line to include my 77 i (province), but i got an
> error "insufficient observation."
> Is 13 in the "keep if country < 13" an arbitrary chosen number because
> countries in the example is more than this.
>
> Please tell me what this means:
>
> forv i = 1(5)60 {
>        local lag = opt[`i']
>        local opt_lag "`opt_lag' `" "' `lag'"
>
> What is the 1(5)60.
>
> I hope somebody can explain. I really need this codes figure out badly.
>
> Thank you so much!!!
>
>
> Majah
>
>
>
>
> use http://fmwww.bc.edu/ec-p/data/hayashi/sheston91.dta,clear
> qui {
> keep if country < 13
> preserve
> levels country, local(levels)
> foreach l of local levels {
>        varsoc rgdp if country == `l'
>        matrix A = r(stats)
>        if `l' > 1 {
>                matrix C = C \ A
>        }
>        else {
>                matrix C = A
>        }
> }
> svmat C, name(col)
> keep if HQ < .
>
> egen id = fill(1 1 1 1 1 2 2 2 2 2)
>
> egen minh = min(H), by(id)
> gen optimal_lag = lag if minh == HQ
>
> sort id opt
> forv i = 1(5)60 {
>        local lag = opt[`i']
>        local opt_lag "`opt_lag' `" "' `lag'"
> }
>
> restore
> }
> levinlin rgdp, lag(`opt_lag')
> *
> *   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/
>
*
*   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/