Statalist


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

st: re: error in my loop


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: error in my loop
Date   Sat, 8 Dec 2007 15:58:03 -0500

Not sure why Stephanie wants to do this, but...
always a better idea to use Stata's time series operators when you can.

program drop _all
program define mydiff
syntax varlist [, order(real 5) ]
di "Differencing `varlist' at order `order'"
matrix D1  = (0.7071, -0.7071)
matrix D2  = (0.8090, -0.5000, -0.3090)
matrix D3  = (0.1942,  0.2809,  0.3832, -0.8582)
matrix D4  = (0.2708, -0.0142,  0.6909, -0.4858, -0.4617)
matrix D5  = (0.9064, -0.2600, -0.2167, -0.1774, -0.1420, -0.1103)
matrix D = D`order'
foreach var of varlist `varlist' {
	forv l=1/`order' {
 		qui gen F`l'`var'=F`l'.`var'
  	}
	mkmat `var' F*`var' , matrix(lags)
	drop F*`var'
	matrix F`var'=lags*D'
	svmat F`var'
}
end

sysuse auto,clear
g t=_n
tsset t
mydiff price mpg
desc F*



Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


*
*   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/



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