%S and %L Functions

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.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

%S and %L Functions

Unread post by rbelhach95 »

Dear Tom,
I would like to use the %s and %l function to implement repetitive task using the dofor loop over the series R1 to R6, when I use the display instruction on the transpose of my calls, I get only NA. Please advise.
Thanks

Code: Select all

OPEN DATA "C: \ Desktop\ R11newset.xls"
DATA(FORMAT=xls,ORG = Col) / R1 R2 R3 R4 R5  
OPEN DATA "C: \ Desktop\ Data_T1.xls"
DATA(FORMAT=xls,ORG=COL) 1 10964 S T1 div r2 T2 K
com M = 61, P=10964
dec rec a T3 ST Call Rtstr
dim a(M,4) T3(M,P)  Rtstr(M,P) ST(M,P) Call(M,P)
dofor y = R1 to R6
boot entries 1 61 1 65360
set draw 1 61 = %s(%l(y)+"(entries)")
      do i =1,M
com a(i,1)=S(i) , a(i,2)=T1(i), a(i,3)=div(i) , a(i,4)=r2(i)
           do j =1, 10964
ewise T3(i,j) = T2(j)-T1(i)
ewise Rtstr(i,j) = (r2(i)-div(i)+draw(i))*T3(i,j)/365
ewise ST(i,j) = %if(T3(i,j)>0, S(i)*exp(Rtstr(i,j)),%na)
ewise Call(i,j) = %if(T3(i,j)>0,exp(-r2(i)*12*T3(i,j)/365)*%max(0,ST(i,j)-K(j)),%na)
           end do j
     end do i
end dofor y
dis tr(Call) y










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

Re: %S and %L Functions

Unread post by TomDoan »

That's not how %S works---you can't include an entry reference inside the character string. It looks like you just need

set draw 1 61 = ([series] y)(entries)

You're also misusing EWISE; it has its own loop over I and J.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: %S and %L Functions

Unread post by rbelhach95 »

Many thanks for your feedback. Yes, it's amazing how the code run much faster after I got rid of the I and J loops. last question, How do I use the dis instruction to get six columns of Call for each R series? I tries to create new series using the function %s as follows

Code: Select all

set %s('Call'+%l(y)) = Call
but I get unassigned error. Many thanks
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: %S and %L Functions

Unread post by TomDoan »

What are you trying to do in that last instruction? CALL is an MxP matrix. How will that fit into a SERIES?
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: %S and %L Functions

Unread post by rbelhach95 »

Thanks for your inputs. I realize that Call is an MxP matrix, i have tried to use com but it doesn't work. I could do one series at a time R1, R2, ... and then use dis to get the call, but I was wondering if I could do it in one shot.
Thanks
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: %S and %L Functions

Unread post by TomDoan »

That's not explaining what you're trying to do. If you're trying to display CALL, what's wrong with doing

disp call

inside the loop?
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: %S and %L Functions

Unread post by rbelhach95 »

Many thanks it works fine. I was putting it outside the loop
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: %S and %L Functions

Unread post by TomDoan »

Again, I would strongly urge you to get into the habit of indenting your loops. It makes it easier to see what's in and what's out.
unitroot
Posts: 6
Joined: Thu Oct 02, 2014 5:50 pm

Re: %S and %L Functions

Unread post by unitroot »

Hello,
I am trying to run LINREG in a DOFOR loop with different variables as dependent variables, and monthly dummies as independent variables, and then extract the residuals of each regression into respective residual variables. The model runs but the generated vectors of residuals are empty. Please help me correct this error. Below is the code.

Code: Select all

dofor i = p1 p2 p3 q3
  linreg i 
  # season{0 to 11}
  set %RESIDS = %s(%l(i)+"_uhat")
end dofor i
Thanks,
unitroot
Posts: 6
Joined: Thu Oct 02, 2014 5:50 pm

Re: %S and %L Functions

Unread post by unitroot »

unitroot wrote:Hello,
I am trying to run LINREG in a DOFOR loop with different variables as dependent variables, and monthly dummies as independent variables, and then extract the residuals of each regression into respective residual variables. The model runs but the generated vectors of residuals are empty. Please help me correct this error. Below is the code.

Code: Select all

dofor i = p1 p2 p3 q3
  linreg i 
  # season{0 to 11}
  set %RESIDS = %s(%l(i)+"_uhat")
end dofor i
Thanks,

I found the solution here: https://estima.com/forum/viewtopic.php?f=32&t=2462
But still would like to know what went wrong in the above code.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: %S and %L Functions

Unread post by TomDoan »

This is backwards:

set %RESIDS = %s(%l(i)+"_uhat")

%RESIDS is the existing series and you're trying to define what is showing on the right. You want

set %s(%l(i)+"_uhat") = %RESIDS
Post Reply