Home > matlab > utilities > dataset > initialize_dataset.m

initialize_dataset

PURPOSE ^

Initializes a structure describing the dataset.

SYNOPSIS ^

function dataset_ = initialize_dataset(datafile,varobs,first,nobs,transformation,prefilter,xls)

DESCRIPTION ^

 Initializes a structure describing the dataset.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function dataset_ = initialize_dataset(datafile,varobs,first,nobs,transformation,prefilter,xls)
0002 % Initializes a structure describing the dataset.
0003 
0004 % Copyright (C) 2011 Dynare Team
0005 % stephane DOT adjemian AT univ DASH lemans DOT fr
0006 %
0007 % This file is part of Dynare.
0008 %
0009 % Dynare is free software: you can redistribute it and/or modify
0010 % it under the terms of the GNU General Public License as published by
0011 % the Free Software Foundation, either version 3 of the License, or
0012 % (at your option) any later version.
0013 %
0014 % Dynare is distributed in the hope that it will be useful,
0015 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 % GNU General Public License for more details.
0018 %
0019 % You should have received a copy of the GNU General Public License
0020 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0021 
0022 if isempty(datafile)
0023     error('Estimation:: You have to declare a dataset file!')
0024 end
0025 
0026 if isempty(varobs)
0027     error('Estimation:: You have to declare a set of observed variables')
0028 end
0029 
0030 % Get raw data.
0031 rawdata = read_variables(datafile,varobs,[],xls.sheet,xls.range);
0032 
0033 % Get the (default) number of observations.
0034 if isempty(nobs)
0035     nobs = rows(rawdata)-first+1;
0036 end
0037 
0038 % Get the (default) prefilter option.
0039 if isempty(prefilter)
0040     prefilter = 0;
0041 end
0042 
0043 % Fill the dataset structure
0044 dataset_.info.ntobs = nobs;
0045 dataset_.info.nvobs = rows(varobs);
0046 dataset_.info.varobs = varobs;
0047 
0048 % Test the number of variables in the database.
0049 if dataset_.info.nvobs-size(rawdata,2)
0050     disp(' ')
0051     disp(['Declared number of observed variables = ' int2str(dataset.info.nvobs)])
0052     disp(['Number of variables in the database   = ' int2str(size(rawdata,2))])
0053     disp(' ')
0054     error(['Estimation can''t take place because the declared number of observed' ...
0055            'variables doesn''t match the number of variables in the database.'])
0056 end
0057 
0058 rawdata = rawdata(first:(first+dataset_.info.ntobs-1),:);
0059 
0060 % Take the log (or anything else) of the variables if needed
0061 if isempty(transformation)
0062     dataset_.rawdata = rawdata;
0063 else
0064     dataset_.rawdata = arrayfun(transformation,rawdata);
0065 end
0066 
0067 % Test if the observations are real numbers.
0068 if ~isreal(dataset_.rawdata)
0069     error('Estimation:: There are complex values in the data! Probably  a wrong (log) transformation...')
0070 end
0071 
0072 % Test for missing observations.
0073 dataset_.missing.state = any(any(isnan(dataset_.rawdata)));
0074 if dataset_.missing.state
0075     [i,n,s,j] = describe_missing_data(dataset_.rawdata);
0076     dataset_.missing.aindex = i;
0077     dataset_.missing.vindex = j;
0078     dataset_.missing.number_of_observations = n;
0079     dataset_.missing.no_more_missing_observations = s;
0080 else
0081     dataset_.missing.aindex = num2cell(repmat(1:dataset_.info.nvobs,dataset_.info.ntobs,1)',1);
0082     dataset_.missing.vindex = [];
0083     dataset_.missing.number_of_observations = [];
0084     dataset_.missing.no_more_missing_observations = 1;
0085 end
0086 
0087 % Compute the empirical mean of the observed variables..
0088 dataset_.descriptive.mean = nanmean(dataset_.rawdata);
0089 
0090 % Prefilter the data if needed.
0091 if prefilter == 1
0092     dataset_.data = transpose(bsxfun(@minus,dataset_.rawdata,dataset_.descriptive.mean));
0093 else
0094     dataset_.data = transpose(dataset_.rawdata);
0095 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005