
version 10
log using contemp1.log, replace


use contempp, clear
sort id date
replace low_est=1000*low_est
replace high_est=1000*high_est
replace price=1000*price
gen lest=ln(low_est)
gen hest=ln(high_est)
gen lprice=ln(price)
gen lav=ln((low_est+high_est)/2)
gen llow=lest
gen lhigh=hest
        

sort date lot

       *This command groups sessions on a single day into one auction
replace date=int(date)

*This drops the few paintings without estimates
drop if low_est==.

drop if price==0
drop if price==.



        *The following commands ensure that lots are numbered consecutively from 1

sort date lot
gen newlot=1 if date~=date[_n-1]
replace newlot=newlot[_n-1]+1 if date==date[_n-1]






        *Create dummy variables for the different auctions
tab date, gen(dat)

gen age=date_ptg
replace lprice=llow+ln(.80) if sold==0
replace price=low_est*.80 if sold==0
sum price low_est high_est len wid 
sum price low_est high_est len wid if sold==1

      *Transforming sample for regressions with covariates (want artists with at least two paintings to avoid colinearities with artist dummies)
encode med, gen(medium)
keep if age~=. & len~=. & wid~=. & medium~=.
egen count=count(lot), by(artist)
drop if count<2
encode artist, gen(art)
encode vat, gen(en_vat)
replace en_vat=0 if en_vat==.
tab art, gen(art)
tab medium, gen(me)


        *Transform age and other variables


egen minage=min(age)
gen minage1=minage-1
gen newage=age-minage1
gen lage=log(newage)
gen lwid=log(wid)
gen llen=log(len)
 
keep if lage ~=. & llen~=. & lwid~=. 


reg lprice  lage llen lwid me1-me19 art1-art302 hal2-hal25

testparm me1-me19
testparm art1-art302
testparm hal2-hal25

predict pprice 
gen index=_b[hal2]*hal2+_b[hal3]*hal3 +_b[hal4]*hal4+_b[hal5]*hal5+_b[hal6]*hal6+_b[hal7]*hal7+_b[hal8]*hal8 +_b[hal9]*hal9+_b[hal10]*hal10+_b[hal11]*hal11+_b[hal12]*hal12+_b[hal13]*hal13 +_b[hal14]*hal14+_b[hal15]*hal15+_b[hal16]*hal16+_b[hal17]*hal17+_b[hal18]*hal18 +_b[hal19]*hal19+_b[hal20]*hal20+_b[hal21]*hal21+_b[hal22]*hal22+_b[hal23]*hal23+_b[hal24]*hal24+_b[hal25]*hal25 

predict resid, resid
predict flag if e(sample)
sum sold if resid>0 & resid~=.
sum sold if resid~=.
sum sold if resid>0 & resid~=. & sold==1
sum sold if resid~=. & sold==1

sum low_est high_est price 
sum low_est high_est price if sold==1

sort id date


gen luscpi=ln(uscpi)
gen lukcpi=ln(ukcpi)
gen difdate=date-date[_n-1] if id==id[_n-1] & id~=.
gen difus=-luscpi+luscpi[_n-1] if id==id[_n-1] & id~=.
gen difuk=-lukcpi+lukcpi[_n-1] if id==id[_n-1] & id~=.
replace difdate=difdate/30
sum price low_est high_est len wid difdate if flag~=.
sum date if lprice>flag & price~=.
sum date if lprice<flag & flag~=.




gen lresid=resid[_n-1] if id==id[_n-1] & id~=.
gen llprice=lprice[_n-1] if id==id[_n-1] & id~=.
gen lpprice=pprice[_n-1] if id==id[_n-1] & id~=.


gen lossgain=lprice[_n-1]-pprice if id==id[_n-1] & sold[_n-1]==1 & id~=.



sum price low_est high_est len wid if id==id[_n-1] & id~=. & lest~=. & pprice~=. & lossgain~=. & lresid~=. 
sum price low_est high_est len wid if sold==1 & id==id[_n-1] & id~=. & lest~=. & pprice~=. & lossgain~=. & lresid~=.


sum sold if llprice>lpprice & lresid~=. & id==id[_n-1] & id~=. & lest~=. & pprice~=. & lossgain~=. & lresid~=. & llprice~=.




sum difdate if lresid~=. & id==id[_n-1] & id~=. & lest~=. & pprice~=. & lossgain~=. & lresid~=.


sum difdate if lresid~=. & sold==1 & id==id[_n-1] & id~=. & lest~=. & pprice~=. & lossgain~=. & lresid~=.

*Note:  difdate is not in logs as the fit is better



*keep if lresid~=. & lossgain~=.



regress llow  lossgain pprice lresid difdate if lresid~=. & lossgain~=., robust
regress lprice lossgain pprice lresid difdate if lresid~=. & lossgain~=., robust 


log close

*this does the graph
*use tempcon, clear
collapse index date year, by(ym)
sort ym
replace year=year+.5 if year==year[_n-1]
gen hal=1 in 1
replace hal=hal[_n-1]+1 if hal==.
gen eindex=exp(index)
label variable eindex "Contemporary Art Index"
label variable year "Year"

label variable hal " "

tw line eindex year, xlabel(1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994) title(Contemporary Art 1992-1994) 

end








