From: Anna Paulsen on 10 Jan 2010 08:47 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hickhb$gf7$1(a)fred.mathworks.com>... > "Anna Paulsen" <Pekingduck82(a)gmail.com> wrote in message <hicia2$puv$1(a)fred.mathworks.com>... > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hice8n$2uu$1(a)fred.mathworks.com>... > > > "Anna Paulsen" <Pekingente82(a)gmail.com> wrote in message <hibb9b$f1p$1(a)fred.mathworks.com>... > > > > Hi, > > > > > > > > I'm having my first stab at Matlab with calculating Newey-West standard errors. > > > > > > > > I searched around and found a code, and I need to define the lags (2). > > > > In the code I found the input is "nlags = "lag length to use". > > > > > > > > Can someone give me a clue how to go about this? Thx for any help! > > > > > > > > I've pasted the code below: > > > > > > > > %PURPOSE: computes Newey-West adjusted heteroscedastic-serial > > > > % consistent standard errors (only se's) > > > > %--------------------------------------------------- > > > > % USAGE: [V,S] = nwse(e,X,nlag) > > > > % where: e = T x n vector of model residuls > > > > % X = T x k matrix of independ vars > > > > % nlags = lag length to use > > > > %--------------------------------------------------- > > > > % RETURNS: > > > > % V is the Newey-West Var-Cov matrix > > > > % S is the spectral density of u = e.*X > > > > % -------------------------------------------------- > > > > > > > > % written by: Mike Cliff, Purdue Finance, mcliff(a)mgmt.purdue.edu > > > > % CREATED 11/17/00 > > > > % MODIFIED 1/23/01 Input e, X separtely; return V, S; df adjustment > > > > % 2/20/01 Allow for system of eqs (multiple e vectors) > > > > > > > > if (nargin ~= 3); error('Wrong # of arguments to nwse'); end; > > > > > > > > [T,k] = size(X); > > > > n = cols(e); > > > > S = zeros(n*k,n*k); > > > > if k == 1 && X == ones(T,1) > > > > u = e; > > > > else > > > > u = []; > > > > for i = 1:cols(e) > > > > u = [u repmat(e(:,i),1,k).*X]; > > > > end > > > > end > > > > > > > > for lag = 0:nlags > > > > rho = u(1:T-lag,:)'*u(1+lag:T,:)/(T-k); > > > > if lag >= 1, rho = rho + rho'; end > > > > wt = 1 - lag/(nlags+1); > > > > S = S + wt*rho; > > > > end > > > > > > > > V = kron(eye(n),(X'*X/T)\eye(k)); > > > > V = V*S*V/T; > > > > > > > > > > > > > > > > end > > > > > > Hi Anna, without running the code, the function expects 3 input arguments, the third one being the maximum lag in the autocorrelation you want to use. There's a typo in the usage section of the help where the input is called nlag and then explained as nlags, which is the way it is in the code. So for the third input argument enter the positive integer you want as the maximum lag. > > > wayne > > > > Thanks wayne - that was less complicated that I thought. > > > > I have run into another issue, though: When I run the code I get the following error message which I have trouble interpreting. Can anybody give a hint? > > > > ??? Operands to the || and && operators must be convertible to logical scalar values. > > > > Error in ==> nwse at 25 > > if k == 1 && X == ones(T,1) > > Hi Anna, again not my area at all, but are you sure the author wants to use cols()? > > at > n = cols(e); and again > at > for i = 1:cols(e) > > If I change those two lines to > > n = size(e,2); > and > for i = 1:n > > The function runs. Again, I'm not sure what it's producing, but hopefully you can make sense of that. Are you inputing the correct size of input arguments, for example, are > e and X matrices with the same number of rows? > > The Matlab function cols() works on database tables. Do you have some other function cols() defined locally? If you type > > >>which cols > > what do you get? > > > Wayne Hi Wayne, thanks for getting back to me once again. There was in fact a cols() function locally which gave n = size(e,2) Sorry, I missed that one. I still get the same error message, however. I guess then the problem must be in the input arguments somehow. I've defined e and X are as vectors with the same number of rows. Their value is displayed as <464x1 double>. Does that cause a problem? - anna
From: Oleg Komarov on 10 Jan 2010 09:12 @Anna Paulsen Btw, when answering delete the e-mail contacts,plz...or it will increase the number of spam received by the users... Have you tried my fcn (if you have the Stats TB)? Oleg
From: Wayne King on 10 Jan 2010 09:17 "Anna Paulsen" <Pekingduck82(a)gmail.com> wrote in message <hiclon$4f6$1(a)fred.mathworks.com>... > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hickhb$gf7$1(a)fred.mathworks.com>... > > "Anna Paulsen" <Pekingduck82(a)gmail.com> wrote in message <hicia2$puv$1(a)fred.mathworks.com>... > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hice8n$2uu$1(a)fred.mathworks.com>... > > > > "Anna Paulsen" <Pekingente82(a)gmail.com> wrote in message <hibb9b$f1p$1(a)fred.mathworks.com>... > > > > > Hi, > > > > > > > > > > I'm having my first stab at Matlab with calculating Newey-West standard errors. > > > > > > > > > > I searched around and found a code, and I need to define the lags (2). > > > > > In the code I found the input is "nlags = "lag length to use". > > > > > > > > > > Can someone give me a clue how to go about this? Thx for any help! > > > > > > > > > > I've pasted the code below: > > > > > > > > > > %PURPOSE: computes Newey-West adjusted heteroscedastic-serial > > > > > % consistent standard errors (only se's) > > > > > %--------------------------------------------------- > > > > > % USAGE: [V,S] = nwse(e,X,nlag) > > > > > % where: e = T x n vector of model residuls > > > > > % X = T x k matrix of independ vars > > > > > % nlags = lag length to use > > > > > %--------------------------------------------------- > > > > > % RETURNS: > > > > > % V is the Newey-West Var-Cov matrix > > > > > % S is the spectral density of u = e.*X > > > > > % -------------------------------------------------- > > > > > > > > > > % written by: Mike Cliff, Purdue Finance, mcliff(a)mgmt.purdue.edu > > > > > % CREATED 11/17/00 > > > > > % MODIFIED 1/23/01 Input e, X separtely; return V, S; df adjustment > > > > > % 2/20/01 Allow for system of eqs (multiple e vectors) > > > > > > > > > > if (nargin ~= 3); error('Wrong # of arguments to nwse'); end; > > > > > > > > > > [T,k] = size(X); > > > > > n = cols(e); > > > > > S = zeros(n*k,n*k); > > > > > if k == 1 && X == ones(T,1) > > > > > u = e; > > > > > else > > > > > u = []; > > > > > for i = 1:cols(e) > > > > > u = [u repmat(e(:,i),1,k).*X]; > > > > > end > > > > > end > > > > > > > > > > for lag = 0:nlags > > > > > rho = u(1:T-lag,:)'*u(1+lag:T,:)/(T-k); > > > > > if lag >= 1, rho = rho + rho'; end > > > > > wt = 1 - lag/(nlags+1); > > > > > S = S + wt*rho; > > > > > end > > > > > > > > > > V = kron(eye(n),(X'*X/T)\eye(k)); > > > > > V = V*S*V/T; > > > > > > > > > > > > > > > > > > > > end > > > > > > > > Hi Anna, without running the code, the function expects 3 input arguments, the third one being the maximum lag in the autocorrelation you want to use. There's a typo in the usage section of the help where the input is called nlag and then explained as nlags, which is the way it is in the code. So for the third input argument enter the positive integer you want as the maximum lag. > > > > wayne > > > > > > Thanks wayne - that was less complicated that I thought. > > > > > > I have run into another issue, though: When I run the code I get the following error message which I have trouble interpreting. Can anybody give a hint? > > > > > > ??? Operands to the || and && operators must be convertible to logical scalar values. > > > > > > Error in ==> nwse at 25 > > > if k == 1 && X == ones(T,1) > > > > Hi Anna, again not my area at all, but are you sure the author wants to use cols()? > > > > at > > n = cols(e); and again > > at > > for i = 1:cols(e) > > > > If I change those two lines to > > > > n = size(e,2); > > and > > for i = 1:n > > > > The function runs. Again, I'm not sure what it's producing, but hopefully you can make sense of that. Are you inputing the correct size of input arguments, for example, are > > e and X matrices with the same number of rows? > > > > The Matlab function cols() works on database tables. Do you have some other function cols() defined locally? If you type > > > > >>which cols > > > > what do you get? > > > > > > Wayne > > Hi Wayne, thanks for getting back to me once again. > > There was in fact a cols() function locally which gave > > n = size(e,2) > > Sorry, I missed that one. > > I still get the same error message, however. I guess then the problem must be in the input arguments somehow. > > I've defined e and X are as vectors with the same number of rows. Their value is displayed as <464x1 double>. Does that cause a problem? > > - anna Hi Anna, how about replacing the if statement with if k == 1 && isequal(X,ones(T,1)) Wayne wayne
First
|
Prev
|
Pages: 1 2 Prev: 3-phase Induction motor (solver) Next: fastinsert vector as single row in Access DataBase |