-
Notifications
You must be signed in to change notification settings - Fork 2
/
supplySide_sigmaEstimation_fullSample.m
156 lines (108 loc) · 4.25 KB
/
supplySide_sigmaEstimation_fullSample.m
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
clear all; clc;
addpath('functions/');
addpath('data/')
%cd('/Users/Lucks/Desktop/movie_project-master')
%addpath('/Users/Lucks/Desktop/movie_project-master/functions/');
%addpath('/Users/Lucks/Desktop/movie_project-master/data/');
%cd('C:\Users\Konrad\Desktop\Studium\Uni-Thesis\Movie project\2017spring - code Simon\movie_project-master - limited version')
%% 0) Import data
% result from demand side
load ('tempdata\demandEstimation14Feb')
ntaste = Model.ntaste;
nmarket = Model.nmarket;
nmovies = Model.nmovies;
n = Model.n;
% market share data etc
load('tempdata/country_size')
load('tempdata/country_name')
load('tempdata/production_budget')
load('tempdata/release_dates')
load('tempdata/sequel')
load('tempdata/prequelT')
%% 1) compute individual utilities for each country/movie at realized taste
% location
indUtilities = ones(n,nmovies,nmarket)*NaN;
for j = 1:nmarket
MarketIndex=j;
for i = 1:nmovies
MovieIndex = i;
c_j = Results.cj_result(MovieIndex,:);
mu_c = Results.muc_result(MarketIndex,:);
sigma_c = Results.sigmac_result(MarketIndex,:);
delta_j = Results.deltaj_result(MovieIndex);
gammapar = Results.gamma_result;
indUtilities(:,i,j) = Simulation_IndividualUtilities(Model,MarketIndex,mu_c,sigma_c,gammapar,c_j,delta_j);
end
end
%% 2) BACKOUT SIGMA
cj_result = Results.cj_result;
%% # ************************
% 1) compute the sequel sigma
% # ************************
seqIndex = find(sequel);
preqIndex = prequelT(seqIndex); % prequelT: t of the prequel
% drop sequels where prequel is missing
missingIndex = preqIndex==0;
seqIndex=seqIndex(~missingIndex);
preqIndex=preqIndex(~missingIndex);
% compute distance prequel - sequel taste location
nseq = length(seqIndex);
distSeqelToPrequel = ones(nseq,ntaste);
for i = 1:nseq
distSeqelToPrequel(i,:) = cj_result(seqIndex(i),:) - cj_result(preqIndex(i),:);
end
sigmaSeq = mean(distSeqelToPrequel.^2);
%% # ***********************************************
% 2) estimate the sigma for all non-sequel movies
% # ***********************************************
% HOW DOES IT WORK:
% - we estimate the sigma from the positive expected profits condition. all movies must
% have started out from a script taste location where expected profits were
% positive
% - 1) this works as long as there are some movies for which
% at the realized taste location profits are negative
% (force pushing for a higher sigma)
% - 2) at the same time we maximize the likelihood of observing the
% observed taste realization (force pushing for a lower sigma)
%% 2.0) drop sequels:
indUtilities = indUtilities(:,~sequel,:);
nmovies = sum(~sequel);
% add data to model structure
Model.country_size=country_size(~sequel,:);
Model.budget=production_budget(~sequel);
Model.nmovies = nmovies;
Model.year = Model.year(~sequel);
Results.cj_result = Results.cj_result(~sequel,:);
Results.deltaj_result = Results.deltaj_result(~sequel);
% compute consumer locations (to save time)
ctilde_i = Model.ctilde_i;
mu_c = Results.muc_result;
sigma_c = Results.sigmac_result;
c_i = ones(n,nmarket,ntaste)*NaN;
for k=1:ntaste
c_i(:,:,k) = ctilde_i.*repmat(sigma_c(:,k)',[n 1]) + repmat(mu_c(:,k)',[n 1]);
end
%% 2.1) verify the condition
% TO DO: compute profits if sigma is 0 at realized taste location and
% verify that some are < 0
%% 2.2) estimate sigma
% Parameters
Model.stepsize = 1;%0.2;
Model.dgrid = 0.1;
% Initial values
x0 = rand(nmovies*ntaste,1);%;zeros(nmovies*ntaste,1)+.25;
lb = zeros(nmovies*ntaste,1);
ub = ones(nmovies*ntaste,1);
% tic
% [J,expprofit,sigma] = SigmaEstimationObjective_fullSample(x0, Model, Results,indUtilities,c_i);
% toc
% bla % END OF CODE
% Params = x0;
% Estimation Loop
options = optimset('Algorithm',Model.algorithm);
options = optimset(options,'MaxIter', Model.MaxIter, 'MaxFunEvals', Model.MaxFunEvals);%,'PlotFcn',@optimplotx);
options = optimset(options,'Display', Model.MatlabDisp, 'TolFun', Model.TolFun, 'TolX', Model.TolX,'UseParallel',false);
[x_2,fval,exitflag] = fmincon(@(Params)SigmaEstimationObjective_fullSample(Params, Model,Results,indUtilities,c_i),x0,[],[],[],[],lb,ub,...
[],options);
[J,expprofit,sigma] = SigmaEstimationObjective_fullSample(x_2, Model, Results,indUtilities,c_i);
bla % END OF CODE