-
Notifications
You must be signed in to change notification settings - Fork 2
/
jun11.m
87 lines (53 loc) · 1.39 KB
/
jun11.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
% use zone*week as market
clear
A = importdata('finaldata_zone_IV.txt');
% A is a structure file
global p s x mkt IV prod
p = A.data(:,1); %price
%rescale to help nonlinear optimization
p = 10*p;
s = A.data(:,2); %share
x = A.data(:,3:6); %product characteristics
mkt = A.data(:,8); % market id
IV = A.data(:,9:12);
prod = A.data(:,7); %product id
%simulate individuals
N = 2;
global yita
%yita = normrnd(0,1,1,N);
% Different draws of consumers across markets
%Although consumer taste changes more across geographic stores/zones than
%across time
T = length(unique(mkt));
yita = zeros(T,N);
for t = 1:T
yita(t,:) = normrnd(0,1,1,N);
end
%R = 10;
%result = zeros(R,6);
%for r = 1:R
options = optimset('GradObj','on');
theta0 = [1,1,1,1,-1,0.5]';
%theta1 = fminunc(@myfun,theta0,options);
lb = [-Inf -Inf -Inf -Inf -Inf 0]';
ub = [Inf Inf Inf Inf Inf Inf]';
%Aeq = [];
%Beq = [];
%A = zeros(1,6);
%A(6) = -1;
%b = 0;
%theta1 = fmincon(@myfun,theta0,A,b,[],[],[],[],[],options);
theta1= fmincon(@myfun,theta0,[],[],[],[],lb,ub,[],options);
%result(r,:) = theta;
%end
%Stage 2
ksi = fun_ksi(theta1);
z = [x IV];
global omg
omg = z'* ksi * ksi' *z;
options = optimset('GradObj','on');
lb = [-Inf -Inf -Inf -Inf -Inf 0]';
ub = [Inf Inf Inf Inf Inf Inf]';
theta0 = [1,1,1,1,-1,1]';
theta2= fmincon(@myfun2,theta0,[],[],[],[],lb,ub,[],options);
%theta2 = fminunc(@myfun2,theta0,options);