Simple linear regression in MATLAB. Something is wrong with my p-values. Stata reports that the p-values should be 0.000 and 0.207, whereas my code reports that they should be 0.0001 and 0.2988. All other statistics are the same as Stata's output. Please help me see the error of my ways.
%number of observations
n = 10;
x = [1.0000, 0.4617; ...
1.0000, 0.7532; ...
1.0000, 0.2145; ...
1.0000, 0.5573; ...
1.0000, 0.5586; ...
1.0000, 0.4195; ...
1.0000, 0.4890; ...
1.0000, 0.9292; ...
1.0000, 0.2540; ...
1.0000, 0.7025];
y = [108.3156; ...
103.0389; ...
170.0043; ...
167.9905; ...
185.0679; ...
190.1774; ...
135.8128; ...
125.5962; ...
146.6757; ...
143.1218];
%calculate coefficients
beta = (x'*x)\x'*y
%calculate residuals
u = y - x*beta;
%calcuatate sum of squares residuals
s_2 = (n-2)\u'*u;
%calculate t-statistics
design = s_2*inv(x'*x);
%calculate standard errors
stn_err = [sqrt(design(1,1));sqrt(design(2,2))]
%calculate t-statistics
t_stat(1,1) = sqrt(design(1,1))\(beta(1,1) - 0);
t_stat(2,1) = sqrt(design(2,2))\(beta(2,1) - 0);
t_stat
%calculate p-statistics
p_stat(1,1) = tpdf(t_stat(1,1),n-2) + tpdf(-t_stat(1,1),n-2);
p_stat(2,1) = tpdf(t_stat(2,1),n-2) + tpdf(-t_stat(2,1),n-2);
p_stat