forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanufact_diminish_000.m
75 lines (62 loc) · 1.7 KB
/
manufact_diminish_000.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
%This m-file runs a Gibbs sampler on the
%manufacturing data, imposing diminishing
%returns to scale
clear;
clc;
randn('seed',sum(100*clock));
load prod_function;
labor = prod_function(:,1);
capital = prod_function(:,2);
output = prod_function(:,3);
y = log(output);
nobs = length(y)
X = [ones(nobs,1) (log(labor./capital)) log(capital)];
%-----------
%Priors
%-----------
V_beta = 10*eye(3);
burn = 5000;
iter = burn + 50*2000;
rts_final = zeros(iter-burn,1);
sigeps = 1;
[bhat stderr tstat sig rsq] = ols(X,y);
gamma_current = bhat;
index_vec = [1 2 3];
a = [-999 -999 -999]';
b = [999 999 1];
for i = 1:iter;
%--------------
%Draw gammas
%--------------
OMEGA = X'*X/sigeps + inv(V_beta);
GAMMA_BAR = inv(OMEGA)*(X'*y/sigeps);
for j = 1:3;
whole_vec = OMEGA(j,:)'.*(gamma_current - GAMMA_BAR);
points = find(index_vec~=j);
vec_keep = whole_vec(points);
mean_part = GAMMA_BAR(j) - inv(OMEGA(j,j))*sum(vec_keep);
var_part = inv(OMEGA(j,j));
gamma_draw = truncnorm2(mean_part,var_part,a(j),b(j));
gamma_current(j) = gamma_draw;
end;
gamma_current
%-----------
%Draw sigma^2
%------------
resid = y - X*gamma_current;
sigeps = invgamrnd( (nobs/2), inv(.5*resid'*resid),1,1);
if i > burn;
rts_final(i-burn,1) = gamma_current(3);
end;
end;
num_keep = ((iter-burn)/50);
keep_rts = zeros(num_keep,1);
for j = 1:num_keep;
tempp = rts_final(50*j,1);
keep_rts(j,1) = tempp;
end;
save man_diminish keep_rts;
[dom ran] = epanech2(rts_final);
plot(dom,ran);
xlabel('Return to Scale');
ylabel('Density');