Regression in Rats

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
c912
Posts: 13
Joined: Sat Dec 03, 2016 3:41 am

Regression in Rats

Unread post by c912 »

Hello,

I have a program under R that I try to perform on ratz but I can't get the same result.

My R program:

x <- 1960:2014
ind <- function(x) ifelse (x<1980, TRUE, FALSE)

pibts2 <- pibts*pibts
regev <-lm(evts ~ pibts+(pibts+pibts2)*ind(x))
summary(regev)

res2<- residuals(regev)
plot(res2, type = "l")

My RATS program:

SET DUM1980 = T>=1960:1.AND.T<1980:1
SET DUM19802 = T>=1980:1
set trendq = pib2*DUM1980
print / trendq

linreg ev 1960:1 2014:1
# constant pib pib2

graph 1
# %resids[/color]

I don't understant why I don't have the same graph for the residuals.

I would also know how to make a graph of the regression (not the residuals):
linreg ev 1960:1 2014:1
# constant pib pib2

Thanks
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Regression in Rats

Unread post by TomDoan »

First of all, I think you have your dummies mixed up. Your R dummy is 1 for <1980:1 and you're creating the RATS dummy to be >=1980:1. If I understand this correctly, you want something like:

set ind = t<1980:1
set pibd = pib*ind
set pidsqd = pib*pib*ind
linreg ev 1960:1 2014:1
# constant pib pibd pibsqd

You don't need to create a dummy for 1980:1 to 2014:1 (which is basically the full sample range)---by doing the CALENDAR instruction, you've already told RATS what the dates are. The R regression doesn't use the "undummied" square, just the linear term and dummied out versions of pib and its square.

You can use @RegActFit to graph the actual and fitted values.
c912
Posts: 13
Joined: Sat Dec 03, 2016 3:41 am

Re: Regression in Rats

Unread post by c912 »

Thank you very much. I still have not exactly the same thing as with R but I will seek a solution thanks to your indications :)
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Regression in Rats

Unread post by TomDoan »

Does the R regression include an intercept by default? What regression are you trying to run?
c912
Posts: 13
Joined: Sat Dec 03, 2016 3:41 am

Re: Regression in Rats

Unread post by c912 »

Does the R regression include an intercept by default?
I don't know.

What regression are you trying to run?

In R, I'm doing:
regev <-lm(evts ~ pibts+(pibts+pibts2)*ind(x))
And for the residuals I have :Image
ANd for the CUSUM test: Image

But in RATS, when I'm using:
linreg ev 1960:1 2014:1
'# constant pib pibd pibsqd
I have for the residuals:Image
And for the CUSUM test: Image
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Regression in Rats

Unread post by TomDoan »

Are you telling me that you want to run a regression, but you don't actually know what regression you're trying to run? That sounds like you need to find someone who works in R to explain what that lm command is doing. However, it looks like you may have more of a problem with getting the data in correctly. (Note that R has a negative outlier at entry 9, and there's nothing at all like that in the RATS output).
c912
Posts: 13
Joined: Sat Dec 03, 2016 3:41 am

Re: Regression in Rats

Unread post by c912 »

I try to do a linear regression on ev with pib + pib² on the first part and pib on the second part. Sorry if I am not clear, I have some difficulty to explain myself, especially in English.

Note that R has a negative outlier at entry 9, and there's nothing at all like that in the RATS output.
→ That's the problem, I don't know why. I use exactly the same data.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Regression in Rats

Unread post by TomDoan »

c912 wrote:I try to do a linear regression on ev with pib + pib² on the first part and pib on the second part. Sorry if I am not clear, I have some difficulty to explain myself, especially in English.

Note that R has a negative outlier at entry 9, and there's nothing at all like that in the RATS output.
→ That's the problem, I don't know why. I use exactly the same data.
I would certainly double check the data after it's read in. (Even the mean is usually enough to verify that you have the same data). Based upon your description, you probably want

set ind = t<1980:1
set pibd = pib*ind
set pidsqd = pib*pib*ind
linreg ev 1960:1 2014:1
# constant pib ind pibd pibsqd

That will give separate intercepts in the two subsamples. (Regression output from both would be *much* more useful than graphs).
c912
Posts: 13
Joined: Sat Dec 03, 2016 3:41 am

Re: Regression in Rats

Unread post by c912 »

Thank you again!

I have watch the regression output and I find what was diferent. I have exactly the same think that in R with:

set ind = t<1980:1
set pibd = pib*ind
set pibsqd = pib*pib*ind
set pibsqd2 = pib*pib

linreg ev 1960:1 2014:1 resmere2
# constant pib pibsqd2 ind pibd pibsqd
Post Reply