problem of procedure

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.
hardmann
Posts: 246
Joined: Sat Feb 26, 2011 9:49 pm

problem of procedure

Unread post by hardmann »

Dear Tom:

I want to estimate repeatedly the local trend and ar(2) model, trend/cycle decomposition. Thus, I try to write a procedure.
I use tow methods to config ar2. However, one is successful, another is failure.

Please help me.

Best regard
Hardmann
Attachments
LTandAR2.src
(1.84 KiB) Downloaded 342 times
LTandAR2decom.src
(2.02 KiB) Downloaded 334 times
US_qgdp_2024Q1.xls
(63 KiB) Downloaded 330 times
US LT&AR2 TEST.RPF
(410 Bytes) Downloaded 338 times
Last edited by hardmann on Wed Oct 30, 2024 10:31 pm, edited 1 time in total.
TomDoan
Posts: 7731
Joined: Wed Nov 01, 2006 4:36 pm

Re: problem of procedure

Unread post by TomDoan »

Shouldn't this be 1 0 1 0?

input c
1 1 0 0
hardmann
Posts: 246
Joined: Sat Feb 26, 2011 9:49 pm

Re: problem of procedure

Unread post by hardmann »

Dear Tom:

In two procedeure, I use different order of states. These have led to errors. I have modified and unified these.
but LTandAR2decom.src till report an error as follows:

## CP24. PROCEDURE/FUNCTION LTANDAR2DECOM compiled with errors. Please correct

if using swf as local frml, error is

## SX22. Expected Type RECTANGULAR[SYMMETRIC[REAL]], Got MATRIX[REAL] Instead
>>>>zeta^2,sigeps^2||)<<<<
## CP24. PROCEDURE/FUNCTION LTANDAR2DECOM compiled with errors. Please correct

Best regard
Hardmann
TomDoan
Posts: 7731
Joined: Wed Nov 01, 2006 4:36 pm

Re: problem of procedure

Unread post by TomDoan »

It's on the line before that. You have SW declared as:

local rect[symm] sw

which looks like it should be just

local symm sw

If you have a problem like that with a procedure, don't do a source instruction. Bring it in as an input file. That way you can do the Edit---Show Last Error to show you the exact line that had the syntax error.
hardmann
Posts: 246
Joined: Sat Feb 26, 2011 9:49 pm

Re: problem of procedure

Unread post by hardmann »

Dear Tom:

I correct it. But problem still reserves.
I am still confused about "Bring it in as an input file."
It always report error. It seems to be related to " function DLMYSetup".

Best Regard
Hardmann
TomDoan
Posts: 7731
Joined: Wed Nov 01, 2006 4:36 pm

Re: problem of procedure

Unread post by TomDoan »

You're inserting this inside the procedure:

function DLMYSetup
compute a(3,3)=ph1,a(3,4)=ph2
compute sw = %diag(||sigxi^2,sigzeta^2,sigeps^2||)
end

You can't do that. You can't nest functions or procedures in-line; the inner one has to be defined first, which wouldn't work as you have done this since the function is using variables from inside the procedure. Your SWF FRML will take care of SW. You can easily redo the reset of A as a FRML[RECT] rather than a FUNCTION.


Open the file. Make it the input file. (Make a second text window as Output). Select All. Run. The errors will go to the Output window and you can use Edit---Show Last Error to show the location where you had the error.
hardmann
Posts: 246
Joined: Sat Feb 26, 2011 9:49 pm

Re: problem of procedure

Unread post by hardmann »

Dear Tom:

On page 58 of the second edition of the RATS Handbook for State-Space Models, the alternative method is gaven, which use the START option on DLM to “poke” the ' values into the proper slots in an otherwise fixed A matrix and then let that (now fixed) matrix
be used in evaluating the log likelihood. The method executes faster and will be useful in more complicated models. When I decomposed the GDP into the local trend ,ar(2) and seasonal components, I use the mothed instead of traditional method that somrtimes does not work.

I am confused why it cannot be used for procedure?


Bset regard
Hardmann
hardmann
Posts: 246
Joined: Sat Feb 26, 2011 9:49 pm

Re: problem of procedure

Unread post by hardmann »

Dear Tom:

The code is right.
There is an incorrect comment on LocalDLM.src as follows

* TYPE=TREND is the local trend model. The two states are the local
* level and the local rate of change.
*
* 1 1
* A =
* 1 0
it should be

* 1 1
* A =
* 0 1

Best regard
Hardmann
TomDoan
Posts: 7731
Joined: Wed Nov 01, 2006 4:36 pm

Re: problem of procedure

Unread post by TomDoan »

As I said, you can use FRML's to accomplish the same thing. You already have a FRML to take care of SW.

local frml[rect] afrml
...
instructions which set the fixed parts of a
frml afrml = a(3,3)=ph1,a(3,4)=ph2,a
...
dlm(a=afrml,...)
hardmann
Posts: 246
Joined: Sat Feb 26, 2011 9:49 pm

Re: problem of procedure

Unread post by hardmann »

Dear Tom:

This method is work. I try altertive which is more effect in more complicated models. Sometimes, the FRML can not get right result.

Best regard
Hardmann
hardmann
Posts: 246
Joined: Sat Feb 26, 2011 9:49 pm

Re: problem of procedure

Unread post by hardmann »

Dear Tom:

If someone want to perform trend and cycle decomposition of GDP for multiple countries, assuming the trend is a second-order unit root and the cycle is an AR(2) process, can it be written as an SRC file for repeated calls, similar to bndecomp.src? It could even include options for the trend, similar to localdlm.src. Additionally, for real-time analysis, it could also be used to repeatedly estimate real-time data.

I attempted to write it but was unsuccessful, so I am seeking your assistance. I believe it is highly necessary to be created.

Best Regard
Hardmann
Post Reply