## Reading in the dataset for question 4, Chapter 3 of Berndt.

Nerlov <- read.table("C:/public/nerlov.txt",header=T)

## Or you can perform the above step via the gui.

## To make sure that SPLus can see the data you attach it

attach(Nerlov)

## Now you can fit the regression through the gui or use the following

## command line syntax.

## The command to do regression is lm (for linear model).

## the " <- " says to assign the output from the lm command

## to an object called nerlov.lm

nerlov.lm <- lm(LNCP3~LNP13+LNP23+LNKWH)

## To get a summary the command is summary

summary(nerlov.lm)

## You can get just the coefficients (useful for bootstrapping by ) coef

coef(nerlov.lm)

## To get a specific coefficient, like the fourth, type in

coef(nerlov.lm)[4]

## Recall from (3.21) in Berndt, that you get r from 1/beta_y, so

## the estimate of r comes from 1/coef(lm(LNCP3~LNP13+LNP23+LNKWH))[4]

## so we get it from typing in

1/coef(lm(LNCP3~LNP13+LNP23+LNKWH))[4]

## Now let's bootstrap this estimate, to get a standard error

## and a bootstrap confidence interval.

## we'll save the bootstrap object in nerlov.boot

nerlov.boot <- bootstrap(Nerlov,1/coef(lm(LNCP3~LNP13+LNP23+LNKWH))[4],B=1000)

## Now we can plot the object or summarize it.

summary(nerlov.boot)

## This sets up a graphics device, ie a screen to graph on.

win.graph()

plot(nerlov.boot)

## It's possible to bootstrap just about anything, for example

## R-squared for the ibm market returns dataset.

## First read in the dataset

markibm <- read.table("C:/public/ibm.txt",header=T)

## Now attach it.

attach(markibm)

## Run the regression

ibm.lm <- lm(IBM ~ Market)

## Summarize it

summary(ibm.lm)

## Check out what is in the summary

names(summary(ibm.lm))

## Rip off r-squared

summary(ibm.lm)$r.squared

## Now we know how to bootstrap r-squared

ibm.boot <- bootstrap(markibm, summary(lm(IBM ~ Market))$r.squared,B=1000)