version 10.0
capture log close

*--------------------------
* Truffle Supply and Demand
*--------------------------

log using chap11, replace
use truffles, clear

* examine data
list in 1/5
summarize 

* reduced form equations
reg q ps di pf 
reg p ps di pf 
predict phat 

* 2sls of demand
reg q phat ps di

* IV/2sls of demand equation
ivregress 2sls  q (p=pf)  ps di 
ivregress 2sls  q (p=pf)  ps di, small 
ivregress 2sls  q (p=pf)  ps di, small first 
estat firststage

* 2sls of supply
reg q phat pf

* IV/2sls of supply equation 
ivregress 2sls  q (p=ps di)  pf, small first
estat firststage

*--------------------------------------
* 2sls using REG3
* This is not discussed in the chapter.
* Enter help reg3
*--------------------------------------

reg3 (q p ps di) (q p pf), endog(q p) 2sls

*--------------------------
* Fulton Fish Market 
*--------------------------

use fultonfish, clear 

* examine data
list lquan lprice mon tue wed thu stormy in 1/5
summarize lquan lprice mon tue wed thu stormy

* estimate reduced forms
reg lquan mon tue wed thu stormy 
reg lprice mon tue wed thu stormy
test mon tue wed thu

* IV/2sls 
ivregress 2sls lquan (lprice=stormy) mon tue wed thu, small first
estat firststage

log close
translate chap11.smcl chap11.txt, replace