成本粘性 stata do文档
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
成本粘性
clear
cd C:\Users\Desktop\成本粘性
insheet using "FS_Comins.csv",clear
destring accper,replace
g year=substr(accper,1,4)
g month=substr(accper,6,2)
drop if typrep=="B"
drop typrep accper
ren stkcd code
rename b001101000 oprev
rename b001201000 cost
replace b001209000=0 if b001209000==.
replace b001210000=0 if b001210000==.
replace b001211000=0 if b001211000==.
gen opcost=cost+b001209000+b001210000+b001211000 keep code year code month oprev opcost
drop if month=="01"
g ym=year+month
order code year ym
sort code year ym
destring year month ym,replace
bys code year:gen rank=_n
bys code year:gen dsales=oprev-oprev[_n-1]
replace dsales=oprev if dsales==.
bys code year:gen dcost=opcost-opcost[_n-1]
replace dcost=opcost if dcost==.
bys code year:gen dcost1=dcost-dcost[_n-1]
bys code year:gen dsale1=dsale-dsale[_n-1]
bys code year:gen increase=1 if dsale1>0 & dsale1 !=.
bys code year:replace increase=0 if dsale1<0
gen increasedsales=dsale1 if increase==1
gen decreasedsales=dsale1 if increase==0
gsort code year -month
bys code year: gen rankm= _n
bys code year:egen rankm1=rank(rankm) if increasedsales!=. replace increasedsales=. if rankm1 !=1
bys code year:egen rankm2=rank(rankm) if decreasedsales!=. replace decreasedsales=. if rankm2 !=1
drop rankm1 rankm2
gen log1=ln(dcost1/increasedsales) gen log2=ln(dcost1/decreasedsales) bys code year:egen log4=max(log2) bys code year:egen log3=max(log1) bys code year:gen sticky=log4-log3 keep code year sticky
duplicates drop
keep if sticky<0
drop if year<=2013
sort code year
drop log1 log2 log3 log4