黃河泉 发表于 2019-4-6 07:10 
请 (ssc install) ascol。
gen date=date(time,"YMD")
. destring code,replace
code: all characters numeric; replaced as long
. format date %td
. xtset code date
panel variable: code (unbalanced)
time variable: date, 01apr2010 to 31jan2013, but with gaps
delta: 1 day
. bys code (date): gen t = _n
. xtset code t
panel variable: code (unbalanced)
time variable: t, 1 to 688
delta: 1 unit
. gen lcl = log(cl)
. gen r = D.lcl*100
(179 missing values generated)
. ascol r, returns(log) keep(vars) tomonth timevar(date) panelvar(code) generate(R)
这是指令
- * Example generated by -dataex-. To install: ssc install dataex
- clear
- input long code str10 time double cl float(date t lcl r month_id) double R
- 9 "2010-05-14" 9.7 18396 30 2.272126 2.822995 0 -23.258328437805176
- 9 "2010-06-29" 8.6 18442 59 2.1517622 -9.213376 1 -12.036371231079102
- 9 "2010-08-12" 9.67 18486 90 2.2690284 -.2065897 2 11.726617813110352
- 9 "2010-09-30" 11.95 18535 120 2.480731 1.858163 3 21.1702823638916
- 9 "2010-11-19" 17.15 18585 151 2.841998 7.693768 4 36.12668514251709
- 9 "2010-12-31" 16.77 18627 181 2.8195915 2.842641 5 -2.2406578063964844
- 9 "2011-02-23" 23.66 18681 212 3.163786 -3.325319 6 34.41944122314453
- 9 "2011-04-18" 20.33 18735 243 3.0120976 -3.051829 7 -15.16883373260498
- 9 "2011-06-01" 16.25 18779 273 2.788093 .1847744 8 -22.400474548339844
- 9 "2011-07-18" 20.89 18826 304 3.0392706 -2.878237 9 25.117778778076172
- end
- format %td date
- format %tm month_id
复制代码------------------ copy up to and including the previous line ------------------
Listed 10 out of 4041 observations
用了ascol后,中间缺了好几个月份,本来应该是从2010年4月到2013年1月的,日数据也是2010年4月1日到2013年1月31日的,调整后就莫名地缺了好几个月份,请问老师这是怎么回事?