Statalist


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

st: Error in my loop


From   stephanie watkins <sewatkins@yahoo.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Error in my loop
Date   Sat, 8 Dec 2007 11:04:38 -0800 (PST)

Hello,

I am new to STATA  and attempting to use this program
for differencing. For some reason STATA returns an
error message stating that it can not find the lag
equation. Any advice would be greatly appreciated:)

Here is my code:

set matsize 800

. 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 D6  = (0.2400,  0.0300, -0.0342,  0.7738,
-0.3587, -0.3038, 
> -0.3472)

. 
. matrix D7  = (0.9302, -0.1965, -0.1728, -0.1506,
-0.1299, -0.1107, 
> -0.0930, -0.0768)

. 
. matrix D8  = (0.2171,  0.0467, -0.0046, -0.0348, 
0.8207, -0.2860, 
> -0.2453, -0.2260, -0.2879)

. 
. matrix D9  = (0.9443, -0.1578, -0.1429, -0.1287,
-0.1152, -0.1025, 
> -0.0905, -0.0792, -0.0687, -0.0588)

. 
. matrix D10 = (0.1995,  0.0539,  0.0104, -0.0140,
-0.0325,  0.8510, 
> -0.2384, -0.2079, -0.1882, -0.1830, -0.2507)

. program define mydiff 
  1. 
.         syntax varlist [, order(real 5) ]
  2. 
.         
. 
.         di "Differencing `varlist' at order `order'"
  3. 
. 
. 
.         matrix D = D`order'
  4. 
.         matrix list D
  5. 
.         
. 
.         foreach var of varlist `varlist' { 
  6. 
.         
. 
.         forv l=1/`order' {
  7. 
.                 gen L`l'`var'=`var'[_n+1]           
            //
>  create the forward lag variables
  8. 
.                 }
  9. 
.         desc L*`var' 
 10. 
.      mkmat `var' L*`var' , matrix(lags)             
          // m
> atrix multiply the lags times the data matrix
 11. 
.      matrix D`var'=lags*D'
 12. 
.      svmat D`var'
 13. 
.      }
 14. 
.      
. 
.         end

. set seed 1

. sort momafqt

. mydiff  cendbpi a1tv alcohol tobacco gestage selfest
depress momafq
> t fchage fmomage furbana furbanb furbanc fmomedu
a1hhkid a1twopar a
> 1poverty, order(5)
Differencing cendbpi a1tv alcohol tobacco gestage
selfest depress mom
> afqt fchage fmomage furbana furbanb furbanc fmomedu
a1hhkid a1twopa
> r a1poverty at order 5

D[1,6]
        c1      c2      c3      c4      c5      c6
r1   .9064    -.26  -.2167  -.1774   -.142  -.1103
equation [_n+1] not found
r(303);


Thanks!!
Stephanie


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
*
*   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–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index