全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
16460 19
2010-09-15
我在用STATA做EVENT STUDY,参考http://dss.princeton.edu/usingdata/stata/analysis/eventstudydataprep.html,现在在做数据准备,我想问的是是不是就是直接COPY命令就可以了?比如变量company_id 是不是我自己导入的数据名称可以代替,比如我是OPEL,那company_id就全部转换为opel?
麻烦大家了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2010-9-15 22:38:43
很急啊,请各位帮忙啊,有偿的也是可以的!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-10-5 15:29:58
不懂。。。。哈哈。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-10-5 22:09:12
the princeton example has two datasets, event data (about the events for each company identified by company_id), and stock data (including stock returns information).

since each company has multiple counts of the same event, you don't need to keep all the event data.

if you have a dataset with some id variable (company_id in the princeton example), then of course you can name it as you like.

please be more specific about your question.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-10-25 22:29:50
这个数据处理的程序对么?有的部分是不是还要自己修改!
use eventdates, clear
by company_id: gen eventcount=_N
这个程序就有问题吧!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-10-26 07:45:42
程序是没有问题的。
我用他提供的部分数据都能运行出来的。
看下面蓝色字体部分

. cd E:\program\stata\event_study\
E:\program\stata\event_study
. insheet using "E:\program\stata\event_study\eventdates.csv",com names clear
(2 vars, 62 obs)
. sort company_id
. save "E:\program\stata\event_study\eventdates.dta",replace
file E:\program\stata\event_study\eventdates.dta saved
.
. by company_id: gen eventcount=_N
.
. by company_id: keep if _n==1
(59 observations deleted)
. sort company_id
. keep company_id eventcount
. save "E:\program\stata\event_study\eventcount.dta",replace
file E:\program\stata\event_study\eventcount.dta saved
.
.
. insheet using "E:\program\stata\event_study\stockdata.csv",com names clear
(4 vars, 390 obs)
. save "E:\program\stata\event_study\stockdata.dta",replace
file E:\program\stata\event_study\stockdata.dta saved
.
. sort company_id
. merge company_id using eventcount
(note: you are using old merge syntax; see [D] merge for new syntax)
variable company_id does not uniquely identify observations in the master data
. tab _merge
     _merge |      Freq.     Percent        Cum.
------------+-----------------------------------
          3 |        390      100.00      100.00
------------+-----------------------------------
      Total |        390      100.00
. keep if _merge==3
(0 observations deleted)
. drop _merge
.
.
. expand eventcount
(8279 observations created)
.
. drop eventcount
. sort company_id date
. by company_id date: gen set=_n
. sort company_id set
. save stockdata2,replace
file stockdata2.dta saved
.
.
.
. use eventdates, clear
. by   company_id: gen set=_n
. sort company_id set
. save eventdates2,replace
file eventdates2.dta saved
.
. use stockdata2, clear
. merge company_id set using eventdates2
(note: you are using old merge syntax; see [D] merge for new syntax)
variables company_id set do not uniquely identify observations in the master data
. tab _merge
     _merge |      Freq.     Percent        Cum.
------------+-----------------------------------
          3 |      8,669      100.00      100.00
------------+-----------------------------------
      Total |      8,669      100.00
.
.
. list company_id if _merge==2
. keep if _merge==3
(0 observations deleted)
. drop _merge
.                  
. egen group_id = group(company_id set)
.
.
. sort company_id date
. by company_id: gen datenum=_n
. by company_id: gen target=datenum if date==event_date
(8647 missing values generated)
. egen td=min(target), by(company_id)
. drop target
. gen dif=datenum-td
.
. *For calendar days:
. *gen difc=date-event_date
.
.
. by company_id: gen event_window=1 if dif>=-2 & dif<=2
(8654 missing values generated)
. egen count_event_obs=count(event_window), by(company_id)
. by company_id: gen estimation_window=1 if dif<-30 & dif>=-60
(8579 missing values generated)
. egen count_est_obs=count(estimation_window), by(company_id)
. replace event_window=0 if event_window==.
(8654 real changes made)
. replace estimation_window=0 if estimation_window==.
(8579 real changes made)
.
.
. tab company_id if count_event_obs<5
no observations
. tab company_id if count_est_obs<30
no observations
.
.
.  drop if count_event_obs < 5
(0 observations deleted)
.  drop if count_est_obs < 30
(0 observations deleted)
.
. set more off /* this command just keeps stata from pausing after each screen of output */
.
. gen predicted_return=.
(8669 missing values generated)
. egen id=group(company_id)
.
.
. /* for multiple event dates, use: egen id = group(group_id) */
. sum id

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
          id |      8669    2.427154    .8592213          1          3
. local N=r(max)
.
.
. forvalues i=1(1)`N' { /*note: replace N with the highest value of id */
  2.         list id company_id if id==`i' & dif==0
  3.         reg ret market_return if id==`i' & estimation_window==1
  4.         predict p if id==`i'
  5.         replace predicted_return = p if id==`i' & event_window==1
  6.         drop p
  7. }
      +---------------+
      | id   compan~d |
      |---------------|
1943. |  1         GM |
      +---------------+
      Source |       SS       df       MS              Number of obs =      30
-------------+------------------------------           F(  1,    28) =       .
       Model |  .621092774     1  .621092774           Prob > F      =  0.0000
    Residual |  3.6790e-06    28  1.3139e-07           R-squared     =  1.0000
-------------+------------------------------           Adj R-squared =  1.0000
       Total |  .621096453    29  .021417119           Root MSE      =  .00036
------------------------------------------------------------------------------
         ret |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
market_ret~n |  -.0017893   8.23e-07 -2174.16   0.000     -.001791   -.0017876
       _cons |   16.50429   .0067618  2440.80   0.000     16.49043    16.51814
------------------------------------------------------------------------------
(option xb assumed; fitted values)
(6530 missing values generated)
(5 real changes made)
      +---------------+
      | id   compan~d |
      |---------------|
2399. |  2      Magna |
      +---------------+
      Source |       SS       df       MS              Number of obs =      30
-------------+------------------------------           F(  1,    28) =  102.18
       Model |  8.59534089     1  8.59534089           Prob > F      =  0.0000
    Residual |  2.35542648    28  .084122374           R-squared     =  0.7849
-------------+------------------------------           Adj R-squared =  0.7772
       Total |  10.9507674    29  .377612668           Root MSE      =  .29004
------------------------------------------------------------------------------
         ret |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
market_ret~n |   .0071517   .0007075    10.11   0.000     .0057025     .008601
       _cons |  -31.10621   8.189216    -3.80   0.001    -47.88105   -14.33136
------------------------------------------------------------------------------
(option xb assumed; fitted values)
(7981 missing values generated)
(5 real changes made)
      +---------------+
      | id   compan~d |
      |---------------|
3378. |  3       Opel |
      +---------------+
      Source |       SS       df       MS              Number of obs =      30
-------------+------------------------------           F(  1,    28) =       .
       Model |   .00298667     1   .00298667           Prob > F      =       .
    Residual |           0    28           0           R-squared     =  1.0000
-------------+------------------------------           Adj R-squared =  1.0000
       Total |   .00298667    29  .000102989           Root MSE      =       0
------------------------------------------------------------------------------
         ret |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
market_ret~n |  -.0000875          .        .       .            .           .
       _cons |   .7557923          .        .       .            .           .
------------------------------------------------------------------------------
(option xb assumed; fitted values)
(2850 missing values generated)
(5 real changes made)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群