Passing arguments to programs

For questions regarding programming in the EViews programming language.

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

dagfinnrime
Posts: 54
Joined: Sat Oct 11, 2008 9:37 am
Location: Oslo
Contact:

Passing arguments to programs

Postby dagfinnrime » Thu Jun 30, 2016 12:01 pm

Hi,

I want to have a code that I can reuse to create "significant-asteriks" next to regression-coefficents in tables.

This attempt works:

Code: Select all

subroutine signif(string %eq, scalar !coef) !sig10 = 0 !sig5 = 0 !sig1 = 0 if {%eq}.@pval(!coef) < 0.01 then !sig1=1 endif if {%eq}.@pval(!coef) < 0.05 then !sig5=1 endif if {%eq}.@pval(!coef) < 0.1 then !sig10=1 endif %ast = "" for %p 10 5 1 if !sig{%p} = 1 then %ast = %ast + "*" endif next endsub ' ..... lots of code, but not in subroutine call signif("eq_of2",3+!case) tab_reg(!r,7+!case) = @str(eq_of2.@coefs(3+!case),"f.4")+%ast
And here comes my question, because lots of variants of the following program doesn't work (the benefit of a program is that it can be called within a subroutine using EXEC-command).

Code: Select all

' Program: Signif_asteriks.prg (in Addin-folder so Eviews finds it) !sig10 = 0 !sig5 = 0 !sig1 = 0 !coef = @val(%1) if {%0}.@pval(!coef) < 0.01 then !sig1=1 endif if {%0}.@pval(!coef) < 0.05 then !sig5=1 endif if {%0}.@pval(!coef) < 0.1 then !sig10=1 endif %ast = "" for %p 10 5 1 if !sig{%p} = 1 then %ast = %ast + "*" endif next
And this is how I call it:

Code: Select all

' lots of code .... exec signif_asteriks eq_of 4 tab_reg(!r,5) = @str(eq_of.@coefs(4),"f.4")+%ast
It produces lots of Asteriks, but in wrong places. I know this because in testing it I replace @coefs with @pval.

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

Re: Passing arguments to programs

Postby EViews Gareth » Thu Jun 30, 2016 1:22 pm

When using exec all program variables are independent between programs. So the parent (calling) program's %ast will not be affected by the child program's calculations.

dagfinnrime
Posts: 54
Joined: Sat Oct 11, 2008 9:37 am
Location: Oslo
Contact:

Re: Passing arguments to programs

Postby dagfinnrime » Sat Jul 02, 2016 1:06 am

Thanks.
For some reason I thought I couldn't call a subroutine from within a subroutine.

So if I want the SUBROUTINE in a program for later reference, I can use a INCLUDE-command, and then CALL it in the program.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest