夏目贵志 发表于 2015-9-21 23:13 
if numofCompany==33 & LossIndicator==1 & year
再请教您一个问题,我代码确实是写好了,但是运行效率极其低下。我电脑配置应该挺高的,CPU i74930xm 4核 八线程,32GB内存。硬件上应该没有问题,在运行以下代码时CPU占用率也很高,CPU每个核心都用上了,stata占用CPU90%以上。
- egen numofCompany=group(Companyname)
- gen LossIndicator=1 if PLforperiodNetincome<0
- replace LossIndicator=0 if (PLforperiodNetincome>0 | PLforperiodNetincome==0 ) & PLforperiodNetincome!=.
- gen Loss=.
- sum numofCompany
- local a=r(max)
- forvalues i=1/`a'{
- forvalues j=2004/2014{
- local d=`j'+1
- qui count if numofCompany==`i' & LossIndicator!=. & year<`d'
- local b=r(N)
- dis `b'
- qui count if numofCompany==`i' & LossIndicator==1 & year<`d'
- local c=r(N)
- if `b'!=0{
- replace Loss=`c'/`b' if numofCompany==`i' & LossIndicator!=. & year==`j'
- }
- }
- }
复制代码我这段代码的目的就是生成Loss这个变量。Loss is Cumulative percentage of sample years that the firm reported a loss.
生成巴基斯坦这个国家的Loss变量并不难,因为公司不多,我现在在生成中国的Loss变量,几天几夜了还没完,请问有没有修改代码的办法?