Near Singular Matrix

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Nano
Posts: 8
Joined: Mon Apr 01, 2013 1:11 am

Near Singular Matrix

Postby Nano » Sun Apr 07, 2013 6:48 pm

Hello..

I try to estimate this model:
yit = ai(Dit<=PD*) + ai(Dit>PD*) + b1iXit(Dit<=PD*) + b2iXit(Dit>PD*) + b3iDit(Dit<=PD*) + b4i(Dit>PD*) + uit where Xit is control variable i=1..5

the main purpose this estimation is to search PD* that minimize SSR, with this codes:

scalar sig_level = .05

' LS method to find the threshold
smpl @all if y<>na and pd<>na and x1<>na and x2<>na and x3<>na and x4<>na and x5<>na
scalar smallest_ssr = 9999999999
scalar lambda_ls = 0


matrix(880,2) ssr
matrix(880,2) likelihood
for !lamdba = 22 to 110 step .1
series I = (PD <= !lamdba)
series I1 = 1 - I
for !i=1 to 5
series X{!i}1 = X{!i} * I
series X{!i}2 = X{!i} - X{!i}1

next

equation eq.ls Y I I1 X11 X21 X31 X41 X51 X12 X22 X32 X42 X52 PD*I PD*I1
ssr((!lamdba -22)*10+1,1) = !lamdba
ssr((!lamdba -22)*10+1,2) = eq.@ssr
likelihood((!lamdba -22)*10+1,1) = !lamdba
likelihood((!lamdba -22)*10+1,2) = eq.@logl
if (eq.@ssr < smallest_ssr) then
smallest_ssr = eq.@ssr
lambda_ls = !lambda
endif
next
ssr.xyline
show lambda_ls

' ML method to find the threshold
c=0
' LS estimate as the initial value for lambda in ML estimation
c(1) = lambda_ls
logl ll
ll.append @logl lgl
ll.append I = (PD <= c(1))
ll.append I1 = 1 - I
ll.append pdI = PD * I
ll.append pdI1 = PD * I1
for !i=1 to 5
ll.append X{!i}1 = X{!i} * I
ll.append X{!i}2 = X{!i} - X{!i}1

next

ll.append res = Y-c(2)*I-c(3)*I1-c(4)*X11-c(5)*X21-c(6)*X31-c(7)*X41-c(8)*X51-c(9)*X12-c(10)*X22-c(11)*X32-c(12)*X42-c(13)*X52-c(14)*PDI-c(15)*PDI1
ll.append var = @var(res)
ll.append lgl = log(@dnorm(res/@sqrt(var))) - log(var)/2
ll.ml(c=1e-20, m=9999)
show ll.output
scalar lambda_ml = c(1)
delete X11 X12 X21 X22 X31 X32 X41 X42 X51 X52 var lgl i i1 pdI*

' model without threshold effect
equation eq.ls y c X1 X2 X3 X4 X5 PD

' likelihood ratio test
scalar LR = 2 * (ll.@logl - eq.@logl)
scalar pval = 1 - @cchisq(LR, 7)
matrix(880, 2) significant
!ubound = eq.@logl + .5 * @qchisq(1-sig_level, 7)
for !i=1 to 880
significant(!i,1) = 22 + (!i-1) * .1
significant(!i,2) = ( likelihood(!i,2)>!ubound )

next
significant.xyline
stop

The Result is NON SINGULAR MATRIX, what the problem is?

thank you in advance,
Nano

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Near Singular Matrix

Postby EViews Gareth » Sun Apr 07, 2013 9:43 pm

Are you sure you don't have perfect colinear itty?

Nano
Posts: 8
Joined: Mon Apr 01, 2013 1:11 am

Re: Near Singular Matrix

Postby Nano » Sun Apr 07, 2013 11:42 pm

Yes I'm sure Gareth. I try to estimate this syntax with excluding PD in endogenous variable too (PD only as a threshold variable) and I check it's collinearity and there is no perfecf collinearity (below 0.5).

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Near Singular Matrix

Postby EViews Gareth » Mon Apr 08, 2013 8:09 am

How did you check the collinearity?

Nano
Posts: 8
Joined: Mon Apr 01, 2013 1:11 am

Re: Near Singular Matrix

Postby Nano » Mon Apr 08, 2013 9:11 am

I made collinearity matrix, Gareth and I found that their collinearity range between 0.2-0.5

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Near Singular Matrix

Postby EViews Gareth » Mon Apr 08, 2013 10:29 am

There's no such thing as a collinearity matrix in EViews. You probably meant that you created a correlation matrix, which is not the same thing.

Code: Select all

create u 10 series y=nrnd series x=nrnd series z = 1+y+x group g x y z show g.cor
In this example, X, Y and Z are perfectly collinear (indeed Z is equal to 1+x+y). Yet they are not particularly strongly correlated.

Nano
Posts: 8
Joined: Mon Apr 01, 2013 1:11 am

Re: Near Singular Matrix

Postby Nano » Mon Apr 08, 2013 10:49 pm

Oh i see..thank you very much Gareth

Nano
Posts: 8
Joined: Mon Apr 01, 2013 1:11 am

Re: Near Singular Matrix

Postby Nano » Tue Apr 09, 2013 4:26 am

Gareth, how can I solve perfect collinearity? Is it just excluding one or more variable that indicated cause it's problem?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Near Singular Matrix

Postby EViews Gareth » Tue Apr 09, 2013 7:51 am

Correct.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest