File: initialize_dataset.m

package info (click to toggle)
dynare 4.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 41,312 kB
  • ctags: 15,840
  • sloc: cpp: 77,029; ansic: 29,056; pascal: 13,241; sh: 4,811; objc: 3,061; yacc: 3,013; makefile: 1,476; lex: 1,258; python: 162; lisp: 54; xml: 8
file content (99 lines) | stat: -rw-r--r-- 3,524 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function dataset_ = initialize_dataset(datafile,varobs,first,nobs,transformation,prefilter,xls)
% Initializes a structure describing the dataset.

% Copyright (C) 2011-2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.

% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr

if isempty(datafile)
    error('Estimation:: You have to declare a dataset file!')
end

if isempty(varobs)
    error('Estimation:: You have to declare a set of observed variables')
end

% Get raw data.
rawdata = read_variables(datafile,varobs,[],xls.sheet,xls.range);

% Get the (default) number of observations.
if isempty(nobs) || rows(rawdata)<nobs+first-1 %case 2: dataset has changed
    nobs = rows(rawdata)-first+1;
end

% Get the (default) prefilter option.
if isempty(prefilter)
    prefilter = 0;
end

% Fill the dataset structure
dataset_.info.ntobs = nobs;
dataset_.info.nvobs = rows(varobs);
dataset_.info.varobs = varobs;

% Test the number of variables in the database.
if dataset_.info.nvobs-size(rawdata,2)
    skipline()
    disp(['Declared number of observed variables = ' int2str(dataset.info.nvobs)])
    disp(['Number of variables in the database   = ' int2str(size(rawdata,2))])
    skipline()
    error(['Estimation can''t take place because the declared number of observed' ...
           'variables doesn''t match the number of variables in the database.'])
end

if size(rawdata,1)~=dataset_.info.ntobs
   fprintf('Restricting the sample to observations %d to %d. Using in total %d observations. \n',first,first+dataset_.info.ntobs-1,dataset_.info.ntobs)
end
rawdata = rawdata(first:(first+dataset_.info.ntobs-1),:);

% Take the log (or anything else) of the variables if needed
if isempty(transformation)
    dataset_.rawdata = rawdata;
else
    dataset_.rawdata = arrayfun(transformation,rawdata);
end

% Test if the observations are real numbers.
if ~isreal(dataset_.rawdata)
    error('Estimation:: There are complex values in the data! Probably  a wrong (log) transformation...')
end

% Test for missing observations.
dataset_.missing.state = any(any(isnan(dataset_.rawdata)));
if dataset_.missing.state
    [i,n,s,j] = describe_missing_data(dataset_.rawdata);
    dataset_.missing.aindex = i;
    dataset_.missing.vindex = j;
    dataset_.missing.number_of_observations = n;
    dataset_.missing.no_more_missing_observations = s;
else
    dataset_.missing.aindex = num2cell(repmat(1:dataset_.info.nvobs,dataset_.info.ntobs,1)',1);
    dataset_.missing.vindex = [];
    dataset_.missing.number_of_observations = [];
    dataset_.missing.no_more_missing_observations = 1;
end

% Compute the empirical mean of the observed variables..
dataset_.descriptive.mean = nanmean(dataset_.rawdata);

% Prefilter the data if needed.
if prefilter == 1
    dataset_.data = transpose(bsxfun(@minus,dataset_.rawdata,dataset_.descriptive.mean));
else
    dataset_.data = transpose(dataset_.rawdata);
end