Computing the standard errors

Dear all,
for my master's thesis, I have to compute the standard errors of the estimated model parameters using a bootstrap approach. Trying to run the file "booti2.m", I obtain the following error:
>> booti2
Index exceeds the number of array elements. Index must not exceed 19.
Error in llfn (line 61)
sigvtr = bigthet(20);
^^^^^^^^^^^
Error in
fminunc (line 233)
f = feval(funfcn{3},x,varargin{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in
booti2 (line 87)
[thetstar,fstar,exitflag] = fminunc(@llfn,bigtheto,options);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Caused by:
Failure in initial objective function evaluation. FMINUNC cannot continue.
>>
Please note, that before I could run the original "booti.m" file with data for France successfully, while now I can't run neither Slovenian nor French file. Thank you so much! Meancimpr.DAT file is in the folder Searching for Starting Values - Full Sample

5 Comments

Torsten
Torsten on 17 May 2026 at 14:15
Edited: Torsten on 17 May 2026 at 14:17
If you want help, you have to supply all necessary files to run your code. You can test this by using the "RUN" button in the menu bar.
run("booti3.m")
Error using load
Unable to find file or directory "meancimpr.dat".

Error in booti3 (line 25)
load meancimpr.dat;

Error in run (line 100)
evalin('caller', strcat(scriptStem, ';'));
Svit
Svit on 17 May 2026 at 14:27
Thank you, but I can't upload .DAT format files:
File format is unsupported for file:meancimpr.dat.
Torsten
Torsten on 17 May 2026 at 14:34
Then use a .zip file in which you include all necessary files.
Svit
Svit on 17 May 2026 at 14:45
Meancimpr.DAT file is in the folder Searching for Starting Values - Full Sample
Torsten
Torsten on 17 May 2026 at 15:18
Edited: Torsten on 17 May 2026 at 15:19
There are two files named "llfn.m" in the .zip file, one in the folder "Searching for Starting Values - Full Sample", the other in the folder "Computing Bootstrapped Standard Errors - Full Sample".
In one of them, there is a line
sigvtr = bigthet(20);
in the other, this line is missing.
From the error message it is obvious that "llfn" is called with an array "bigthet" with only 19 instead of the necessary 20 elements. So the llfn-version with an expected length of 20 for "bigthet" cannot be used (or bigthet has to be modified before the call to llfn).

Sign in to comment.

 Accepted Answer

dpb
dpb on 17 May 2026 at 15:06
Edited: dpb on 18 May 2026 at 16:13
Since LLFN is the objective function of a call to fminunc, I'd refer you back to the documentation and prior discussions we had about how it (fminunc) works to determine the size of the solution vector, and therefore the required dimensions ot the starting estimate and solution vectors in that function.
With @Torsten's observation that there are multiple LLFN m-files apparently for different purposes with the same name, that appears to be the issue.
We don't have any clue about how the original author organized his code, but from there being different folders/directories for the different purposes, it appears you may need to change your working directory to the correct one for the particular task you're after so the files there will be found in preference to others of the same name (see <How MATLAB resolves functions>).. The better solution would have for them to have been named differently so they wouldn't be confused -- and maybe even reflect their purpose? What a novel idea!
This illustrates even more the importance I've noted before of not continuing to treat this code as a black box; you've got to become intimately familiar with what is there and how it is organized and intended to be used.

5 Comments

Svit
Svit 19 minutes ago
Edited: Svit 9 minutes ago
Many thanks to both. I changed the directory and now I can successfully run both French and Slovenian operation.
However, I am having major issues at running the final, third, step of my master's thesis. Please see the test.m file in attachment. The input file seems to be pvqlrsb.txt. I thoughed it was produced in previous two steps for Slovenia, but newly created file includes identical values as French original. Do you have any clue how to replace French data for Slovenian? The file used in previous two steps, Slovenia_centered3 is not required in the code apparently. Thank you so much!
Analyzing the code, I came to a conclusion that file est.m is possibly another input file to test.m, but I'm confused by pvqlrsb.txt. Are there two input files?
dpb
dpb on 19 May 2026 at 12:21
Edited: dpb 3 minutes ago
" I came to a conclusion that file est.m is possibly another input file..."
It (est.m) is, as the extension suggests, another m-file, and is
% EST.M: Function estimates sticky price model of the business cycle
% similar to the setting developed in Ireland (2003).
%
%
% O.Roehe (2011)
function result=est(vecdate);
% load data, select sample, and detrend
global ct it mt pt rt bigt scalinv
load meancimpr.dat;
end
as the first line says, clearly another function....I would again refer you to the documentation and function and <MATLAB>. At a bare minimum at least go through the "Getting Started" and top-level "Programming" sections thoroughly enough to grasp the difference between a function and a data file. A prepared and fully packaged application written in MATLAB might be able to be used as a black box tool but this code is far removed from being that.
This function (est) has, however, like another before been corrupted from what was the original intent (and the typical and more proper way of using functions) of passing the input data in as a dummy argument vector (vecdata) by loading another data file meancimpr.dat and also what look like the same global variables as previous code used plus a couple more. This is, as noted before, risky because of the behavior of global variables -- they're going to be whatever was left over by those names in the working scope, whether wanted or not or, depending upon the content of the LOADed .dat file, maybe they're being defined in it -- no way to know without much more forensic work.
As for which data set is in a file of any given name, that will depend upon the last code run that wrote/SAVEd a file of that name in the current working directory. Again, reusing the same file names for different purposes is risky; you have no way to keep them straight as to which file contains what. Some function will have SAVEd the file with that name with the particular country's data; but using the same name so isn't disntinguishable from the name. Without using a fully qualified filename (one containing both the name and the specific folder), MATLAB writes in the current working directory and the problem is you probably.are now not in the same working directory as when ran that particular case. Or, another possibility is that for checking purposes you reran the other country and the code silently overwrote the file so now the second country data no longer exists. That's (only one of) the (many) problem(s) with what the original author did and why blindly following that code without making changes to use distnict names that are identifiable as to the file content is so problematical (and, consequently, so confusing for you to know what you've done and where particular results may be)..
Again, find the SAVE commands; there's where whatever is written is done -- I would yet again suggest you set breakpoints and use unique file names that are identifiable instead of continuing to blindly try to run somebody elses's code that you don't understand.
ADDENDUM
NOTA BENE: The text file may not have been written with SAVE -- given the rest of the code, probably was, but not necessarily. Look for the file name to be sure to find it, not just SAVE. If did use SAVE, it will have to have used the '-ascii' parameter in MATLAB, not positive about what Octave behavior is with SAVE with a .txt extension on the file name. We already know it saves its .mat files as 1D text vectors, not 2D.
v=rand(5,1);
save v.txt v
whos -file v.txt
Name Size Bytes Class Attributes v 5x1 40 double
type v.txt
MATLAB 5.0 MAT-file, Platform: GLNXA64, Created on: Tue May 19 16:05:54 2026 □□□□□□□□□□IM□□□□P□□□x□ãc``□□b6 æ□Ò À å□hF0fd(□Ò□@¬□Ä□ä¤orM¸c□ôìï©□ó□ØoHÝRc~î□ý□µ□_վݵßVøÌAxÂS{□□·□º
shows that just defining a filename extension as something other than .mat doesn't change the SAVEd file from being a native .mat file in MATLAB.
Moral: If these codes were written for Octave, behavior may not be what is expected if run in MATLAB just as was the issue two months ago in other thread. Only reading the code to see what it actually does will answer the question, and what writes this partciular file isn't in the m-files you've attached--it must be buried in one of those inside the .zip file that I'm not ambitious enough to go dig into.
ADDENDUM SECOND
"...the problem is you probably.are now not in the same working directory ..."
Another possibility is, of course, that this particular .txt file wasn't created by any of these codes at all, but was/is inteded to be created from external data or yet another piece of code...we don't know and can't tell without digging through the the whole morass.
dpb
dpb about 20 hours ago
Edited: dpb 14 minutes ago
"...Slovenia_centered3 is not required in the code apparently."
Or, maybe the doctor renamed it externally? We have absolutely no way to know what may have been done nor what it is nor its intended purpose, presuming it had/has one.
ADDENDUM
Maybe it was/is supposed to be the one that computes the GLOBAL variables???? Dunno, but it's yet another possibility. Check the list of global variables in it and compare to the est function list that is augmented with a couple of others that weren't in prior code.
It is worth noting that good code practices would have avoided a lot of these issues (or made them much easier to debug / track down). Specifically: avoiding GLOBAL variables, LOADing into an output variable, using a proper MAT file format, etc.
dpb
dpb 1 minute ago
Edited: dpb 1 minute ago
Indeed, if only were communicating with the orginal author...

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Products

Release

R2025b

Asked:

on 17 May 2026 at 13:39

Edited:

dpb
about 4 hours ago

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!