Good afternoon,
I am looking for advice on good practice, and for sample code for programming an iterative estimator in Stata.
For concreteness say I have a system of two equations:
(1) y = x'b + e
(2) w = z'g + v.
I want to implement the following procedure due to Telser, L. G. (1964). Iterative estimation of a set of linear regression equations. Journal of the American Statistical Association, 59(307), 845-862.
Estimate (2) by OLS, get the residuals v(0) = w - z'g(0).
Estimate modification of (1) by OLS: y = x'b(0) + a*v(0) + error. Get the residual e(0) = y - x'b(0).
Estimate modification of (2) by OLS: w = z'g(1) + c*e(0) + error. Get the residual v(1) = w - z'g(1)
Estimate modification of (1) by OLS: y = x'b(1) + a*v(1) + error. Get the residual e(1) = y - x'b(1).
Estimate modification of (2) by OLS: w = z'g(2) + c*e(1) + error. Get the residual v(2) = w - z'g(2)
................. Repeat until b(n) converges
I did some reading over the internet, and a couple of issues came up:
1. Stata does not have a function to evaluate the maximum element of a vector. (Mata apparently has, but I would prefer not to switch between Stata and Mata if possible).
I would have naturally defined tolerance as something like Do the above procedure until max(b(n)) - max(b(n-1))<0.0001. Apparently I am not able to do this in Stata.
2. The only matrix function that I found relevant for the problem of defining tolerance was mreldif(X,Y). Then I encountered some reactions of Stata that I cannot really understand: matrix functions that return scalars sometimes are treated as scalars, sometimes not treated as scalars:
that is, the last two assertions went through (so I can use this in defining the loop) but the first failed for reasons not entirely clear to me. mreldif returns a scalar, why would Stata think that I am using a matrix in the first assertion?
So for such and other Gotchas, I thought to ask first how people in the know set up such iterative loops.
I am looking for advice on good practice, and for sample code for programming an iterative estimator in Stata.
For concreteness say I have a system of two equations:
(1) y = x'b + e
(2) w = z'g + v.
I want to implement the following procedure due to Telser, L. G. (1964). Iterative estimation of a set of linear regression equations. Journal of the American Statistical Association, 59(307), 845-862.
Estimate (2) by OLS, get the residuals v(0) = w - z'g(0).
Estimate modification of (1) by OLS: y = x'b(0) + a*v(0) + error. Get the residual e(0) = y - x'b(0).
Estimate modification of (2) by OLS: w = z'g(1) + c*e(0) + error. Get the residual v(1) = w - z'g(1)
Estimate modification of (1) by OLS: y = x'b(1) + a*v(1) + error. Get the residual e(1) = y - x'b(1).
Estimate modification of (2) by OLS: w = z'g(2) + c*e(1) + error. Get the residual v(2) = w - z'g(2)
................. Repeat until b(n) converges
I did some reading over the internet, and a couple of issues came up:
1. Stata does not have a function to evaluate the maximum element of a vector. (Mata apparently has, but I would prefer not to switch between Stata and Mata if possible).
I would have naturally defined tolerance as something like Do the above procedure until max(b(n)) - max(b(n-1))<0.0001. Apparently I am not able to do this in Stata.
2. The only matrix function that I found relevant for the problem of defining tolerance was mreldif(X,Y). Then I encountered some reactions of Stata that I cannot really understand: matrix functions that return scalars sometimes are treated as scalars, sometimes not treated as scalars:
Code:
. mat a = 1 . mat b = 1 . mat diff = mreldif(a,b) . assert diff<0.001 matrix operators that return matrices not allowed in this context r(509); . assert diff[1,1]<0.001 . assert el(diff,1,1)<0.001
So for such and other Gotchas, I thought to ask first how people in the know set up such iterative loops.
Comment