% lab 4

clear all;

% Problem 1

data = load('dairy.txt');
vl = 1./data(:,1);
w = data(:,2);
developed = data(:,3);
n = length(w);

disp('********************************')
disp('Problem 1')
myols(log(vl),[ones(n,1) log(w) developed]);
disp('********************************')
disp('')

% Problem 2

num = xlsread('cgss05.csv');
n = size(num,1);

income = num(:,1);
female = num(:,2);
edu = num(:,6);
expr = num(:,7);
rural = num(:,4);

disp('********************************')
disp('Problem 2 (1)-(3)')
myols(log(income),[ones(n,1) edu expr female rural],1);
disp('********************************')
disp('Problem 2 (4)')
myols(log(income),[ones(n,1) edu expr female rural edu.*female],1);
disp('********************************')
disp('Problem 2 (5)')
myols(log(income),[ones(n,1) edu expr female rural edu.*female rural.*female],1);
disp('********************************')
disp('Problem 2 (6)-(7)')
myols(log(income),[ones(n,1) edu expr female rural num(:,10:36)],1);
disp('')

% Problem 3

data = load('lfp.txt'); % Mroz (1987) study of labor supply behavior of married women.
lfp = data(:,1); % A dummy variable = 1 if woman worked in 1975, else 0
wa = data(:,5); % Age
we = data(:,6); % Education attainment
faminc = data(:,13); % Family income
mtr = data(:,14); % Marginal tax rate for women
kl6 = data(:,3); % Number of kids under age 6
k618 = data(:,4); % Number of kids between 6 and 18
kids = (kl6+k618>0);

n = length(lfp);
y = lfp;
x = [wa wa.^2 we faminc kids];
disp('********************************')
disp('Problem 3 (1)-(3)')
myols(y,[ones(n,1) x]);

disp('********************************')
disp('Problem 3 (4)-(6)')
[b,dev,stats] = glmfit(x,y,'binomial','link','probit');
disp([b stats.se stats.p])

disp('********************************')
disp('Problem 3 (7)')
x = [wa wa.^2 we kids mtr];
[b,dev,stats] = glmfit(x,y,'binomial','link','probit');
disp([b stats.se stats.p])

disp('********************************')
disp('Problem 3 (8)')
[b,dev,stats] = glmfit(x,y,'binomial','link','logit');
disp([b stats.se stats.p])





