|
maodeng 发表于 2013-1-28 13:13 ; s/ _5 ]1 q* r7 P6 f+ F
. hello 300236' Z$ j) @" p; S2 Q0 Z
statement out of context4 i8 R" H7 a! t7 S
r(119);
) ~9 ^" ^8 g9 P( T) t& r. M抱歉,最近太忙了2 j. v6 Q% ]' J2 g& d' {9 P0 g
: n$ ^$ m2 w5 T& Q, E- {( K300236 我用下面的程序试过,没问题
4 `/ S6 }& d7 [7 t( Y. L4 u3 _7 d5 | Z) W- l. _- e( F% v2 _# _
你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试" p# H2 y% o/ x4 i3 Y
6 G8 C& s3 r6 k' S3 {capture program drop hello! V2 y5 c, D+ ~7 i. F
; k0 S& C: {4 Jprogram hello1 q. y1 u) W# q2 ]. U- y: F
8 r& ~' \9 O, I' Q: j/ k
quietly {7 F$ S8 X) m( o7 o8 O
& m6 R/ L# m W. L. y2 y; Y7 O3 W
clear3 n0 G3 t9 g) T5 K; v; P
( e: x; Y0 i$ q
cd D:\stock\test\source
% s8 p7 }& `+ _ x" w6 c
1 \% X" r. K! dinsheet using `1'.txt9 }2 c' @. y3 S
0 d" | \ ^ s8 s: x- ?' G
keep if v5>0
0 i( E. |' O! V4 k: w 4 Y! J+ k# i+ B4 a# u; k/ G! Z
gen vt=_n! b+ a0 l0 u- X# b2 H+ V: O
8 }+ J7 z* Z4 K9 b: F
tsset vt
2 h' U% s8 }5 \4 B0 J1 R+ g% U: Z/ }* X2 d0 x* R: \, X
gen zf=D1.v5
: j. k5 l1 Y7 w
; Z. y0 ^4 @4 O gsort -v1
- l! n4 ?2 {/ }" x3 {$ j$ _% R. I! H/ Z7 s0 b% {
gen avol=v7/v5
% M5 j' I% N8 T; t% S
8 r4 W: _. d/ g# z% a keep if avol>02 \+ {& _( N& k
: g$ M, n7 o) |& \ drop vt0 Z& M( H+ C3 m: c7 Y9 g
% s) B9 Z; T" M gen vt=_n
! {3 s+ U" Y6 V
1 F8 u/ O! b, O* o- q tsset vt2 y8 K8 F( Q, K
( ^+ h3 S* G2 i# |
sum v5 [aw =avol]
) M) a _" P5 u- ^9 y% M: Z7 I! Y
gen amean=r(mean) in 1
. f3 w ?6 H$ Z2 N- c& m ' r+ Q/ y; d( M4 k) ~4 f; p+ a
* 总加权平均值 amean
& g( ^. d! n/ d
7 z E; I1 e' M' J' S
: c T. }+ G9 \- \3 O4 p keep in 1/240
t& `3 F) ]( }* B9 e. w( b
+ y- |- j# O) m) [& _# } sum v5 [aw =avol]# [$ x8 |4 a1 B u0 _/ P, l0 i
0 ^+ d* {2 H* q# T
gen mean240=r(mean) in 1+ }8 I/ M. H4 g- y2 a( N
" @" I ]6 K1 ]. D+ b
*240加权平均值 mean240# Y- E8 m$ `" A7 I* F) B
3 O! d( B$ |6 m* |( M set obs 500
! V& y) l* f# g' O t' v" |! V6 @$ f9 j
kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
6 h1 f( w/ }0 T9 Q ) q. B9 e8 A, o
*240 kdensity(dx240 dy240)
3 N4 W B2 |$ N; V $ y# k2 d( t: N+ y4 [
sum dy2400 K4 ^/ F4 K2 M2 Z
6 w8 R1 G# }. g, {0 E gen yxis=r(max) in 1
C; F" L9 V: q
, i# U X. ^; C* x gen yxis2=yxis/2
0 A+ O; A5 z i' ~ W
! q/ F. f: o5 ]( h *yxis: x- l# R: U5 \
" ^+ ^* P; m$ ~& i8 Z5 J+ l7 ~& T5 \" _ gen dy240max=r(max)6 `1 W+ o2 y" `0 ?. O: h# d
# g. t' L! [ s# Y# }% n4 A! j: w+ J4 a gen dy240minp=r(min)6 l5 h z0 d! l6 s* U' Q5 @: F* M
6 D( V5 ^: m. N* h& m% P gen vtt=_n
# |" W# j# D+ \3 J: S" Q! Y! T+ g) Z% |6 r( g1 d- I4 a9 N
tsset vtt
5 W, Q3 ]0 s5 h9 s5 ~ |: d. M, |$ h$ d
gen ddy240=D1.dy240/D1.dx2405 P- u/ G4 Y! g; N8 _
4 {) J8 U$ R+ W) U: q# `- H+ t sum ddy2403 n5 n8 ~9 o8 y, T- K! @
/ R* c# z, S: x& H: n+ ?/ j% f
gen ddy240max=r(max) N4 y# [/ i4 P1 I( S. j4 Y
4 x& d6 R2 c+ d2 d gen ddy240min=r(min); _9 c5 v$ Y: D
) K" i Q8 g( k# j7 L gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)% |" L4 H1 i7 z% i& s% M# b) b
3 s% S- A* W$ M, y8 r sum ddy240g7 U; V0 Q. Y& _/ Y7 _1 z
. J& M* L$ E2 U# G7 K7 o& W8 I* `
gen yxis3=r(min) in 1
0 a) x9 |; a4 |. e. V% F
, D* H" _0 n6 j& N5 K gen yxis4=0 in 1- _6 f8 p" b) P9 d: \ m! R6 i, ^
5 H8 d3 D$ y' L- x) y* x' U. e
*ddy240g 8 z# Z2 |. p3 |; `6 ~
, c6 v5 s, T( z2 k* O2 c
% D0 c# S* Z! N. w. @* k preserve & l s: `' Z" U- t( d/ _% U" |, u
( X5 m( w! H" u4 j" Q4 K sum v5 [aw =avol]
# r$ I/ `" v& ?9 j 9 ^ |# S& y4 U% N3 |
keep if dx240<r(mean)
3 {9 z* U2 r+ z! E' Z2 o+ [$ m 3 ?/ p9 l8 p" @+ R! r6 l- M
sum ddy240
4 D$ V+ a& q: P/ v9 c2 K) @' t8 E0 a 4 _) t3 K, m# P& P# `( B
if r(min)<0 {
$ g& ~, k" J7 T: c( }& }9 Q: M
( B4 Y" l" r8 p2 |4 ]; A keep if ddy240<=0/ y5 U! o3 i; t) i4 b2 `+ {
8 h9 a$ T" [/ E count
# c. p i; X' o " E( i+ S: \" a& h
if r(N)>2 {- r! M7 v0 H% F) Y7 _9 f* O
; h/ J3 S( e8 ^: A1 `- r9 e pkexamine dx240 dy240$ `, l2 s$ M' k3 V2 t! o' f6 u* M" S6 U
6 m9 g% K. L, c. K
local tempminp=r(tomc) V5 C9 @3 q5 o3 [
restore 2 |3 L; c8 Z: G
}. p" Q; Y1 n k( ~; u* E5 U
) }. ~) C. [! A# V" K" y
else {
; N8 _2 y1 i5 M6 F9 C
. [3 n" b: L$ `3 Y% \8 d di "cannot find minp"2 ^+ g5 Z7 w" U2 V& r1 m
# W7 u1 c5 H" S' m0 n% X) W2 H
restore - |' x p) _( M4 x, J3 L0 R
sum dx240
" Z+ P5 Y+ k# Q local tempminp=r(mean)* z! T# c% h D. _. x; L. f( L
6 J3 c0 [2 M6 E. n0 k2 ^3 P0 _
}
; b$ M# G4 L4 I; K/ i. j6 }4 A; F }
1 E$ [* x6 t7 m) }" w0 E3 i7 ?2 O: I else {! H% b* ^* i( c1 l
% A+ g$ ]3 F+ z# ]) E0 c% y keep if ddy240<=r(min)
' U3 P! u& S: C' A' M! ~ [
* _# k! {. H5 {6 i5 f! o: E/ s1 }% R sum dx240$ b$ v5 t) M9 {( Z" b5 }9 P
, ~* j! O$ r) g, b0 T local tempminp=r(min)
* _) U5 z% k; e& t2 A( ?* O restore . O1 o; y7 ?' [
}2 O1 Q- w1 M2 F7 B( z: p
' M* e" J$ n3 g3 p$ D- l- W& w
( C% A) O N: W6 N/ [
V3 B* ^1 D% s9 x+ k# |/ m7 t. O% g
gen minp=`tempminp' in 1
: h; T) e6 v3 \& J: u I *240 minp
6 T6 b% o3 `3 U/ H) v
! m4 j2 e! B0 l+ x- `/ t' K+ c8 V0 Z4 V. g0 [
. r E5 F+ q8 q! M& s) p preserve
3 R6 J' z% D; ~" u% Q" ` G ) t- T+ j) W! p9 ~; P, D9 e
sum v5 [aw =avol]
1 _* _6 T* m7 Y
( |" C" n: \) P$ [0 I% t keep if dx240>r(mean)) x: \- Z9 O' y! m" i
* N* m6 ?; ?# t% @7 b' \/ R
sum ddy240 B. S4 u0 m' ^) J g7 f# X- g2 }
6 A8 b3 F( G8 s8 g+ w p* Q- J
if r(max)>0 {& N7 x4 l1 a' E+ a" n
8 W, ~0 J) R8 a2 _ T' M keep if ddy240>=0
8 x% V% U( ?5 j1 h- C! }
1 B. H& ^3 e$ {* @* c' } count- i8 A* ~ }' ?% ~
- y5 s1 ]) E, u& @) h4 [- ^% n if r(N)>2 {
, ?1 J n) W3 d6 r( Z" y
% z. B; @- v( [9 e) c3 \, B/ q: ]& ] pkexamine dx240 dy2408 b5 c3 @4 }7 I! b3 a+ C6 J
0 m' e5 U7 v7 _3 N$ H
local tempmaxp=r(tomc)
" Q" e" k) j- |; m. \ restore ! q, s. x/ A& y, n h8 }
} ~* w& a- O; N" |, n# \' d
" a1 K+ ^' q. c2 V+ k( E
& z. M7 ~! {3 F9 X9 Q7 ~ z; v* B( ^ else {
9 Y u3 Q0 ]6 x% K restore
5 `0 f. q3 h2 k" Z di "cannot find maxp"8 B; O, L1 M9 p
: k* J; Q- f! x8 R5 L M
& P( R" ^, q6 Q! O5 k- T
sum dx2403 E9 q' i! I" I0 ~8 {8 S+ B. i7 J
local tempmaxp=r(mean)
C4 h; A* S& t
& C# a! Y' Y' J2 Y8 f) ?# ?8 i }
! H* {* A& H; p1 F
: `0 X8 h0 c4 r9 Y0 K" j }! @: u- Z/ N0 ]. C$ Q/ ^9 v; H
; ^ g+ w# T2 u4 R4 n8 m. b else {
3 T2 u8 C$ E H2 f/ m# d: D
9 W! O; x$ D! B$ Q, l keep if ddy240>=r(max)7 f; [, L- n2 s1 N* K
4 h6 w, ]9 t$ [$ B% |: t sum dx2406 r. T5 q, J( T" g& Y: \
% W M8 e( Z6 F. `
local tempmaxp=r(max)
6 {. i2 M2 I, D# D6 r; m: Z) e& R restore
0 k. }3 i! Y* w* R' r1 ~) I }
- ] u( `% y6 F- s
8 O3 }2 |, }, o0 C* D/ z3 D, }
' b/ G8 p0 D& ^9 i; \4 X : z! T6 n* W7 l; P- [) z# _9 D# i0 j
7 N( ~6 M( D* [. | gen maxp=`tempmaxp' in 1& a7 n- ~" E$ C. g) o9 F
! ]% h7 i+ C( s4 }" B
*240maxp1 h5 f Z3 t. d" z( ~2 K! f
. b: y7 s+ m' I! u4 H' c; { X! H
, V* Q) n# f a6 y. u
*-------------ddy240pminp左侧高峰值-----
6 S: ?3 X, M6 [! n: A6 u' d/ z
& h9 H: K( t, X* z: u6 { preserve
) ~ q( Q: S7 b3 @/ X ]5 g. W7 ? / o# L9 o+ P2 N" v- b
keep if dx240<`tempminp'
8 x$ ?+ n5 n6 S+ O$ C# q
' B! Z3 T. n! s, F" u5 V0 k keep if ddy240>0
; K1 |) B8 c# c8 l% `
; L R D2 @+ ^& Y& t count
3 H8 m# t' w6 s2 G0 u 9 R. G1 t/ h3 X: d7 H
if r(N)>2 {; v8 Y; E( l" F) K+ R2 E( u
+ `# \2 ?# ?% j7 E pkexamine dx240 ddy240
( \$ o9 `( m3 G: w+ j 2 Z1 P( k: x" e. M* J
local tempminphddy240=r(tomc)
1 a* Z7 i6 y+ ?5 l* e. M; n restore7 A, ]3 }8 ~4 G, T0 Y# L
}; L( ]& T1 C) [
/ a9 Z1 {# p/ R" O
else {: ^4 d0 z+ f! q a) C) f) t
restore
V* N: S1 F- p1 O di "cannot find pminphddy240"( L! k: P/ Q: R4 b% ]- v
; C( b& m2 T/ X7 @+ `
1 v7 [! Y# Z( t7 w/ K# N! _* d
sum dx240
/ ?1 a8 Z7 y: s( } local tempminphddy240=r(mean) + P) j6 z5 ?0 J5 [
4 T; `! V% c6 i0 C. |1 P }- k% p Y/ d+ `" ~" R; r8 `
}
! X# U4 N( i+ L3 J* F ; Q+ g' f* |( D4 F
6 ~% F0 V( B5 T% r, c9 g0 ~
8 Q5 i/ J4 Y5 ~7 f
$ S4 L5 |& W/ E6 c " m' X8 C p; V% ?( \: q$ q
( \( x( ?0 m9 S U6 X! _
gen pminphddy240=`tempminphddy240' in 1
/ e& ?$ d3 {% }5 r" E
# h& d. b- ~4 f) w( q) Z2 F; o 8 v' z4 [4 u g& w0 E* ` Y2 v
*-------------ddy240pminp右侧低峰值 -----------------8 `5 \: V( O4 j. {! y* M5 y
preserve
, N3 ~8 {$ F' ^) b5 o8 ~ t1 q / f! E ^- ?9 O
keep if dx240>`tempminp'. u& A! F1 w! ?) k" R
* @+ X3 b; ]/ o2 U+ N( ~
keep if dx240<`tempmaxp'; {0 E. s4 b$ n; v
& R% | |- G7 H6 O
keep if ddy240<0 f$ m5 z0 A# Q. a0 l
h7 ~2 R6 y3 N
gen temddy240=-ddy240
2 x9 P4 R; S$ ~" O4 Z
) {! A/ N8 E- j ~9 S count
, u# }# l O0 h# ]. \
0 {* f( s8 Q3 G" U' O# E0 T if r(N)>2 {
" o* p% J' O/ k
, Y3 j% j2 u6 h/ _7 V pkexamine dx240 temddy240
/ U! t- S" d+ T! t1 s& D1 t' P% o * {- B% `" d: A' P+ O
local tempminplddy240=r(tomc)
6 i9 d: ^$ p% S7 v, A restore( W9 ^3 K. w. j+ h
}
n" {- s* V/ O" v) p- w) _. E & m7 u. T7 V: ?9 e, V9 p
else {
. o. R! w% z% {" A& x/ ? 4 }& e8 \: u5 f/ |- u, g9 B
di "cannot find pminplddy240"
0 Y# F I- m# H4 F restore3 W- ~& V& S1 R; @8 g' n% w" h8 [ t
! }# \. |2 d c7 A0 G( c3 w; U# r
sum dx240 N2 j0 e6 A: b
local tempminplddy240=r(mean)
( k* N: m6 d7 ^
3 C* m# l/ F; h# g0 M, D( J F* Y% }% Z/ @
}8 U+ T& V- A+ J+ a# c% j Z
5 C% m# c* b$ ^9 W
! A( t+ \1 t, r9 P" e
# ^: E. l7 }, B) z
2 F0 J! U8 D3 [! y; X6 k, p) L % K# H% v0 q1 U* u6 q
gen pminplddy240=`tempminplddy240' in 19 B7 e4 O& T" \/ V, S* J2 O. S
3 K8 x% _+ c' H# E
*-------------ddy240pmaxp左侧高峰值 -------------------. D* ?; K1 n! F: i. b# U* x0 m
3 l- G0 Q! A r( e4 M. |1 I2 X
preserve
7 R% h, C M. T) p3 Y, E3 h9 l j9 W
+ I& G2 {: e2 J. z keep if dx240>`tempminp'
3 O* `6 g7 K4 O# d 8 E& A1 Q5 n1 S: @% ?4 E
keep if dx240<`tempmaxp'
U f. Z! i3 h! g3 C # i. H. R A5 k; T# X9 S
keep if ddy240>0
0 @' ?- x" B9 U9 t5 p9 Y! u" L y- l0 B count0 o7 p' q9 ?# m' H
+ w3 |4 e5 J; [7 A% q; y9 A! r
if r(N)>2 {! G$ F: c4 Z* ^" U# ~3 ~3 I
. Y5 L+ h: ~9 p! I; P: W9 @
pkexamine dx240 ddy2406 {- c8 q0 S% O8 M) Z$ {
/ k1 {6 N o& A) P$ m# J+ p0 O local tempmaxphddy240=r(tomc)
/ V4 G: T2 ^4 ^3 V8 i
7 R1 {& M g8 s6 E restore
( `0 h" u/ p6 M& b }4 M0 N4 }6 i" |% c
9 d2 o7 k2 g+ a0 z, K# L4 ` else {4 A5 ^6 Y% W+ ]- D& B1 T( ?- s
2 N9 N' v1 h% V9 i
di "cannot find pmaxphddy240"
- Q+ S& ^5 E# d+ n1 d n$ ~2 J# i restore% |* L# W8 y) F: x5 c: n( a6 c
6 G. ^; B% X% q0 h, k' n" g% _4 i' n sum dx240' X# o2 A. H3 Q8 ^1 L! m9 G, B, _
local tempmaxphddy240=r(mean)
3 f5 o+ r1 Y5 }. e1 _ u$ M
! A0 } l2 M& v, d# b: d - `6 I( H4 i* O% ~& f( ^
}! z5 X( I9 @) ~; Y5 _5 o* S
+ ^ n7 \) c7 L6 A
6 s: A. m" T) p9 U
: F% j& d) F; W, D; }! G
" S9 T+ }' d2 g
0 }. s; \ Q4 V+ ] 9 }* A7 e3 A: k" y6 s* T
gen pmaxphddy240=`tempmaxphddy240' in 14 x0 g) E1 i3 D5 Q+ j" O3 S2 x
) l" A: m7 ]2 Z9 t
9 l) o8 q0 q% W1 x, h *-------------ddy240pmaxp右侧低峰值 -------------------3 i7 N. A6 h: ^
( u' d* I! T/ ^, N8 z7 K. p6 Q! o
preserve
* m! ?- l( o8 @8 T0 E
J$ @* M% v0 q/ f, { keep if dx240>`tempmaxp'
* n2 W( n6 t& a3 ]" _' j4 O+ T
* l; o- j7 z- {, i gen temddy240=-ddy240
6 T; w$ p K9 Y/ j* \, d 3 X& s( q- V0 E6 K, g0 m
keep if temddy240>04 u$ _2 U- e% J! T; m
& ^/ |4 x! p) g" H) Q% m3 l
count% [) |4 x; G$ H
; K$ H: C# ^4 i
if r(N)>2 {
2 j2 w# N; L8 O( R+ W6 M6 Y8 o; a % J2 z/ a9 M; X& x
pkexamine dx240 temddy240
5 d8 x5 Y' Z, m# T h0 ^$ a, _9 S( f
local tempmaxplddy240=r(tomc) : B# O" Z# v9 u K0 l+ ~
restore- t- O# m* O9 ^7 |
}
) G% V( G1 O! v( R/ b: }3 ]$ I ) F+ D3 \+ a- a, @/ y N
else {/ d% l6 b h: [/ r4 h4 k f
restore
( o% x2 L, P g- p6 P$ J2 F0 L N di "cannot find pmaxlhddy240": f; D' G/ ]2 t1 M1 }
* V5 k, l/ U: V5 g
( n7 F3 P! A) b$ `" i
sum dx2405 x5 {; T4 A' \5 ~. A) o+ d
local tempmaxplddy240=r(mean) in 1* Y$ a; U8 B. l( `) O G
& {2 j3 N# A; s7 S6 V
- ]$ k8 r8 G2 {
}- m6 c3 R; [( K1 Y- Z
6 w8 S& ~! \1 T. R6 m0 ^( {
! @2 r$ ?- q5 g, W
1 y5 w2 [9 d' Z , t$ u5 y$ m( e6 j3 L0 \
0 V" `9 p1 [' t3 f' Z
a1 A! K0 f4 S! T: V/ L, h& ~ gen pmaxplddy240=`tempmaxphddy240' in 1: `' P- g9 [4 H9 L) D; T' J: v
7 @- [; D$ Y# y) J *-------------------------------------
' R0 e+ Y2 _5 e; i' M3 o # d8 Z5 y- n. |6 K7 C* K) ^) ?
gen price5d=v5 in 1/20$ m/ S7 L' r2 y- z3 R0 c
+ ]+ L( V0 s: }/ C; G# T0 O gen price5yy=_n in 1/20# r" V. F/ \ b! U; w" _( k6 r
/ `% {4 L+ B$ w gen price5y=price5yy*(dy240max-dy240min)/20
% R. m; v1 z' k/ A( g1 d - j9 L h& _1 G3 ^7 h
*price5y &price5d
5 S! b) V* \# j# A) a' H & g0 |4 i1 F% X3 u& H* _9 v
gen priceny=price5y in 1
0 m5 \! w* T" ]( ]. n" M+ O1 {
9 M% {7 j" _0 k. e" Y5 J gen pricen=v5 in 1. h7 ^6 s! }& I. x$ h
" N. F& O# M( g: R
8 I p( P& h0 n$ U+ Q- I6 q x
*priceny &pricen! P$ O$ a4 p. s
7 f' K/ y7 x) C
4 z5 a2 d% B' d, l! ]9 m$ n0 k *-------------------------graph------------------& ` W4 f' E9 M0 @
- ], I- d/ |& E# z" K tw(line dy240 ddy240g dx240)(spike yxis mean240, lc(red))(spike yxis maxp, lp(-) lc(black))(spike yxis minp, lc(black)) (scatter yxis2 mean240,lc(red) msymbol(+) mlabel(mean240) lc(red))(scatter yxis maxp,msymbol(+) mlabel(maxp) lc(black))(scatter yxis minp, msymbol(+) mlabel(minp) lc(black))(scatter yxis4 pminphddy240, msymbol(O) c(l[-]) mlabel(pminphddy240))(scatter yxis3 pminplddy240, msymbol(O) c(l[-]) mlabel(pminplddy240))(scatter yxis4 pmaxphddy240, msymbol(O) c(l[-]) mlabel(pmaxphddy240))(scatter yxis3 pmaxplddy240, msymbol(O) c(l[-]) mlabel(pmaxplddy240))(scatter price5y price5d, msymbol(O) mfc(black) mlc(black) c(l[-])) (scatter priceny pricen, msymbol(O) mfc(red) mlc(red)), title("`f'") xtitle("`1'") ytitle("density") legend(off)
\3 [) Y# m; O' z0 S- q2 }8 D. z) w. Z3 y8 v
* ---------可选项目----------------------+ B6 W3 K7 J2 j% F {: u4 ^
*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean))
" N8 ?. Q% W8 M}
# R0 E }$ U1 vend
: z% A; I% a) J/ X: f |
|