Page 1 of 2
Loop Intial Values over MAXIMIZE Instruction
Posted: Mon Feb 25, 2013 8:29 am
by rbelhach95
Dear Tom,
I would like to loop over my second data file of initial values with the MAXIMIZE instruction, I was able to loop over my FRMLS using the first data file of 49 industries, but having problem with the initial values, I have 8 parameters of initial values for each of the 49 industries. Please see attached code. Your help is very much appreciated.
Rachid
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Tue Feb 26, 2013 10:25 am
by TomDoan
1. Get rid of the ALLOCATE 49 instruction.
2. What you want is com mux=muxi(count), muT = muTi(count),...
3. Before you do anything else, I would recommend that you go very carefully through your formula to make sure it is actually calculating what you want. With some of the more complicated subexpressions, I would suggest doing the calculation by hand and checking against what the RATS calculation is giving. The poor behavior of the BFGS estimates would not be expected if this were (as written) an infinitely differentiable function.
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Thu Feb 28, 2013 6:02 am
by rbelhach95
Dear Tom,
Thank you so much for your input. I got rid of the ALLOCATE 49 and it worked beautifully. I have rechecked my FRMLS again as you have recommended and they are written correctly. With the actual data convergence seems fine, I have one question: Is there a way to code (a loop e.g.) the program so that in the case of nonconvegence , a different piters with the simplex or more subiterations are executed until convergence is attained? I have looked in the user guide for such options in the MAXIMIZE instruction but could not find it.
Thank you
Rachid
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Thu Feb 28, 2013 5:43 pm
by TomDoan
Use %CONVERGED, which is defined by almost any non-linear optimization instruction. See
http://www.estima.com/forum/viewtopic.p ... 711&p=6418
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Fri Mar 01, 2013 4:24 am
by rbelhach95
Dear Tom,
Thank you so much for your reply. My question was not about how not exclude the vector of coefficients when convergence is not attained, but rather, whether the code could be executed again with a different set of piters or increasing the subiters limit e.g. until convergence is obtained. Your help is very much appreciated
Rachid
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Fri Mar 01, 2013 10:30 am
by TomDoan
rbelhach95 wrote:Dear Tom,
Thank you so much for your reply. My question was not about how not exclude the vector of coefficients when convergence is not attained, but rather, whether the code could be executed again with a different set of piters or increasing the subiters limit e.g. until convergence is obtained. Your help is very much appreciated
Rachid
Same idea.
estimation
if %converged==0
do estimation again perhaps with different options
I wouldn't recommend putting looping back (i.e.
:again
estimation
if %converged==0
goto again
as that's asking for an infinite loop. You
could do
do tries=1,5
estimation
if %converged==1
break
end do tries
which would limit you to five tries.
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Fri Mar 01, 2013 5:36 pm
by rbelhach95
Dear Tom,
Thank you for your inputs. Please see the attached code, I have tried the infinite loop as written on your last email, but I get an error. What I really need is to first get rid of non-convergence output cases as they mess up my mean square error and bias. I don't see why this wouldn't work for example:
if %converged ==1
break
else {
compute k = k
}
This way each time nonconvergence occurs, new data is generated until convergence is achieved. May be I am misplacing this conditional statement at wrong place in the code. Please advise
Thank you
Rachid
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Fri Mar 01, 2013 7:10 pm
by TomDoan
The middle set of code should have had a big red / across it. *Don't* do that. Do either the first or the last. And yes, you just want to restart the optimization, not regenerate the data.
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Mon Mar 04, 2013 12:12 pm
by rbelhach95
Dear Tom,
Thank you for your help. I was able at least able to eliminate the cases where estimation does not convergence, I am using the REPORT instruction (please see code attached) How do you use the copy option to save the created table to my desktop for example? Thank you so much.
Rachid
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Mon Mar 04, 2013 6:58 pm
by TomDoan
open copy mycopyfile.xls
report(action=show,window = 'Estimation')
report(action=show,format=xls,unit=copy)
will show one copy on the screen and send one to the file mycopyfile.xls
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Tue Mar 05, 2013 3:52 am
by rbelhach95
Dear Tom,
Thank you for your reply, your help is very much appreciated. I was able to generate the xls table, but it seems that it includes the nonconvergence cases as well, I don't know why this is still happening after I impose the condition if %convergence==1. Here is my question:
I would like to create a dummy variable (vector) which takes 1 if the maximum likelihood converges and 0 otherwise. is it possible to define a dummy variable in RATS? if so how can I find it in the user's guide?
Please see attached code
Thank you
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Tue Mar 05, 2013 6:28 am
by TomDoan
Code: Select all
report(row = new, atcol = 1) mux muT sigmax1 sigmaT1 sigmaTx1 sigmax2 sigmaT2 sigmaTx2
if %converged == 1
com mux_hat(k) = mux, muT_hat(k) = muT
com sigmax1_hat(k) = sigmax1, sigmaT1_hat(k) = sigmaT1
com sigmax2_hat(k) = sigmaTx1, sigmaT2_hat(k) = sigmax2
com sigmaTx1_hat(k) = sigmaT2, sigmaTx2_hat(k) = sigmaTx2
report(row=current, atcol=1, align=decimal) mux_hat(i)
report(row=current, atcol=2, align = decimal) muT_hat(i)
report(row = current, atcol=3, align = decimal) sigmax1_hat(i)
report(row = current, atcol=4, align = decimal) sigmaT1_hat(i)
report(row= current, atcol=5, align = decimal) sigmaTx1_hat(i)
report(row = current, atcol=6, align = decimal) sigmax2_hat(i)
report(row = current, atcol=7, align = decimal) sigmaT2_hat(i)
report(row = current, atcol=8, align = decimal) sigmaTx2_hat(i)
I'm not sure what you want from this, but
(1) This adds a row to the REPORT before it tests %CONVERGED
(2) The IF needs { ... } around the controlled statements. As written, the only instruction that doesn't get executed on %CONVERGED==0 is the first COMPUTE.
It looks like you want K to count only the examples which converge. To do that, you either want to loop back to regenerate the data when it doesn't converge, or change from a do loop to a WHILE:
compute k=0
while k<=n {
....
if %converged==1 {
compute k=k+1
report(row=new,...)
com mux_hat(k)=mux,...
}
}
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Tue Mar 05, 2013 9:41 am
by rbelhach95
Dear Tom,
Thanks a lot for your reply. I have amended the code a bit like you have suggested and you are right I am trying to regenerate the data as I mentioned in on of my previous emails whenever nonconvergence occurs. However please see attached code, I get the following error and (N=5) separate tables. not one xls sheet. Please advise! Thank you
## Unassigned 613
The Error Occurred At Location 1803 of loop/block
Line 32 of loop/block
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Tue Mar 05, 2013 9:50 am
by TomDoan
You're doing the REPORT(ACTION=DEFINE,..) inside the loop, and also doing the REPORT(ACTION=SHOW,...) inside the loop. The first needs to be before the WHILE, the latter needs to be after the final }
Re: Loop Intial Values over MAXIMIZE Instruction
Posted: Tue Mar 05, 2013 10:49 am
by rbelhach95
Dear Tom,
Thanks for your very useful insights. Please see the amended code, I still get many separate tables and the same error in my previous email. Please advise!
Best
Rachid