%% Import data from spreadsheet
% Script for importing data from the following spreadsheet:
%
%    Workbook: C:\Users\ssundar\Desktop\CleaningData\archive2\3_SentimentAnalysis\LoughranMcDonald_MasterDictionary_2014.xlsx
%    Worksheet: LoughranMcDonald_MasterDictiona
%
% To extend the code for use with different selected data or a different
% spreadsheet, generate a function instead of a script.

% Auto-generated by MATLAB on 2017/07/18 12:48:20

%% Import the data
[~, ~, raw] = xlsread('.\LoughranMcDonald_MasterDictionary_2014.xlsx','LoughranMcDonald_MasterDictiona','A2:S85132');
raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''};
stringVectors = string(raw(:,[1,19]));
stringVectors(ismissing(stringVectors)) = '';
raw = raw(:,[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]);

%% Replace non-numeric cells with NaN
R = cellfun(@(x) ~isnumeric(x) && ~islogical(x),raw); % Find non-numeric cells
raw(R) = {NaN}; % Replace non-numeric cells

%% Create output variable
data = reshape([raw{:}],size(raw));

%% Create table
dictionary = table;

%% Allocate imported array to column variable names
dictionary.Word = stringVectors(:,1);
dictionary.SequenceNumber = data(:,1);
dictionary.WordCount = data(:,2);
dictionary.WordProportion = data(:,3);
dictionary.AverageProportion = data(:,4);
dictionary.StdDev = data(:,5);
dictionary.DocCount = data(:,6);
dictionary.Negative = data(:,7);
dictionary.Positive = data(:,8);
dictionary.Uncertainty = data(:,9);
dictionary.Litigious = data(:,10);
dictionary.Constraining = data(:,11);
dictionary.Superfluous = data(:,12);
dictionary.Interesting = data(:,13);
dictionary.Modal = data(:,14);
dictionary.Irr_Verb = data(:,15);
dictionary.Harvard_IV = data(:,16);
dictionary.Syllables = data(:,17);
dictionary.Source = categorical(stringVectors(:,2));

%% Clear temporary variables
clearvars data raw stringVectors R;