Page 1 of 1

%S and %L Functions

Posted: Mon Jun 09, 2014 6:24 pm
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











Re: %S and %L Functions

Posted: Mon Jun 09, 2014 9:29 pm
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.

Re: %S and %L Functions

Posted: Tue Jun 10, 2014 7:13 am
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

Re: %S and %L Functions

Posted: Tue Jun 10, 2014 2:25 pm
by TomDoan
What are you trying to do in that last instruction? CALL is an MxP matrix. How will that fit into a SERIES?

Re: %S and %L Functions

Posted: Tue Jun 10, 2014 3:03 pm
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

Re: %S and %L Functions

Posted: Tue Jun 10, 2014 4:15 pm
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?

Re: %S and %L Functions

Posted: Tue Jun 10, 2014 4:44 pm
by rbelhach95
Many thanks it works fine. I was putting it outside the loop

Re: %S and %L Functions

Posted: Tue Jun 10, 2014 6:59 pm
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.

Re: %S and %L Functions

Posted: Sat Jun 03, 2017 9:32 pm
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,

Re: %S and %L Functions

Posted: Sat Jun 03, 2017 9:50 pm
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.

Re: %S and %L Functions

Posted: Sat Jun 03, 2017 10:06 pm
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