|
maodeng 发表于 2013-1-28 13:13 2 ?' O" L, s7 g4 `
. hello 300236" @1 S/ M* T( Q& F" T2 X5 Z& k1 b
statement out of context# Z: A. w+ \! L3 t" m
r(119);
+ @$ b; H3 n$ H; l( @抱歉,最近太忙了( ^ A6 S' K1 i3 I& B' `
9 J/ \+ h1 z4 `$ P6 u2 n300236 我用下面的程序试过,没问题
: U) K5 l H6 P" h! P4 ~# b( T7 J3 Y5 v
你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试
6 }& t( k7 J3 f6 m" K8 y1 a! M7 {- y3 o% s, M1 }8 _( N. B# c
capture program drop hello6 P/ c! ]5 J4 w" K1 l1 b' i
: j5 S) d' F: V+ F
program hello
9 B5 ]0 f1 m' p. F
4 o: ?, |( y# N; W2 \+ x5 W% r* T quietly {
3 z+ a% Z" M1 t$ a# v8 G" A
) b9 P' [5 w0 p0 X* Bclear
5 R, b% z" I1 O8 J, [. z4 r) c- @' O9 |
cd D:\stock\test\source. Z0 N- H; u. I+ L7 H$ j M2 e
/ W1 L6 P" q3 L9 c! Rinsheet using `1'.txt5 k3 w* k9 t/ k5 R+ ]: v0 w' |
' K& @4 y3 j4 h$ L0 X) I! f
keep if v5>0
; k- p; [9 w6 C W" H3 O' k 5 |* V; Z7 v3 m- `. J
gen vt=_n
) f; J) a5 N8 L ) V8 _1 h; a. x+ A/ Z
tsset vt0 [. Y* Z, K, j2 v }
b: C* f; U# z* ~& b: u8 f
gen zf=D1.v5
2 R+ y9 V. `+ ~1 Q
j& \% [, S. Z% ~9 F3 k; R gsort -v1' ? @# s7 B; P- ]/ g* g) W
) y, A; N% |/ R0 K2 v8 t
gen avol=v7/v5
3 M# k' ^* O) _. g
+ }6 a9 y2 ?( |) f7 S/ f4 D keep if avol>0/ k( M4 |5 i) i+ k. P6 f/ I" S7 ~
" ~: ^. l" @7 q& m( k
drop vt* U+ a: x5 f# w$ q1 D
5 Z" l+ @4 G h! _! N0 F, E1 P5 Y
gen vt=_n* t' ^6 c$ r! F8 {. J1 ~
0 }, C+ o/ t9 @2 D6 X L# c8 \
tsset vt
6 A q6 B2 U) M6 d( V
6 s4 ^/ k: O0 M7 C4 [ [( x/ L4 S) i sum v5 [aw =avol]
' g& }; O! M# Z1 N# r d* m
+ M' C0 Z4 Q: Z+ L; ]/ \9 R gen amean=r(mean) in 17 @* w" N* w) u( f; n
% }# w! l2 t" z# k- z$ ~
* 总加权平均值 amean$ U, @2 u& k, s7 G
- I" a5 ?" ?: c( _
% D* k0 H0 e( S1 L keep in 1/240
1 b! t) J. ~2 w* K9 u
0 w; u% |! |3 Q$ P8 Z) G1 G sum v5 [aw =avol]! q; C8 J& L4 s2 \+ ]
7 n* e# R( @8 m) ]9 Q gen mean240=r(mean) in 1
& ]" I- q2 n: z/ L; L |6 [, A: \ 1 ]/ V3 |. R, O7 M* u5 @: ]$ Z' X
*240加权平均值 mean2402 ]4 a0 u8 J% S7 G& _
5 K/ L% S0 O) E1 k9 L
set obs 500 1 ?; b! J( Y, U* {! U1 N1 D
5 }: J7 w# H! I8 ~8 }+ i kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph+ z/ g8 d# D: e" n! t
% r; H8 t& d+ ^ *240 kdensity(dx240 dy240)
, K% ~3 |; _3 N8 x* ]
: F5 y! k! s: A J9 R sum dy240& z& E% n! x8 @' N1 Z9 w
; K, ~& ^! K( s3 K1 \$ y+ G( i gen yxis=r(max) in 1
0 O* O+ ?. j' C0 U+ U% c
& r* @# W3 |* C1 G+ E& o gen yxis2=yxis/22 ^6 k5 M$ r8 r8 u l
. H+ m2 ^& c$ n+ _ *yxis
# U9 \5 p. [; P9 W# z; Y
+ u7 W: f+ d- q! p/ U: j1 @& _% H gen dy240max=r(max)2 e5 k1 O5 m H( ^4 o4 [
6 J8 z' ?! M* ]) R. T gen dy240minp=r(min)4 A. A) I( z/ H5 j1 H# [. d. @
3 q! E) y8 P3 K% n gen vtt=_n
! `& n/ Z0 \9 n, C2 k8 _4 _( O
0 A6 X7 ~0 ` x* H tsset vtt
0 R8 V: I. G9 k, v5 U0 Q
% Q# J' T8 @1 \ gen ddy240=D1.dy240/D1.dx240$ `1 n# N# F1 M9 M3 V5 Y7 v
, d8 f7 s, ^4 D: d1 Z* W sum ddy240( c+ ?5 b; {' a" }
3 X! R/ b0 A- B+ Y; e a" ?; K gen ddy240max=r(max)
6 h2 ]6 x0 B" w2 [9 v: X$ u3 ~1 Y7 J - [# U2 J5 ~, L. Y. h6 G
gen ddy240min=r(min)5 o6 S$ w) i& |/ D5 t0 V
) o6 D0 s, A* h& O" n
gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)/ u& h# [/ n. T% l
! P: D+ j2 f/ i. Z+ k sum ddy240g
* |2 W3 ?( ^5 }& O2 n" y + [. ]2 u- \ ^4 S" \# J
gen yxis3=r(min) in 1
8 S1 N5 ?6 K- u3 \6 X% G* D# F
: y% F. a1 e% y$ l) w. _ gen yxis4=0 in 1& Y6 r1 c" S1 J) y& v
! T4 f* A& @9 A/ E
*ddy240g 8 a. J4 ^" T* l# ^* j8 j
* p3 I4 c. b) P; r7 l }& U1 B
( R: J- p% U& K, \& |/ X6 B7 G preserve ' j1 n. A X+ f
; w& `% l; F* o5 s. N8 g0 R sum v5 [aw =avol]+ r' q( R( j% d2 x: B' K. P7 `$ ?
2 R$ E, h2 `' m- Q5 e
keep if dx240<r(mean)3 J( n8 V$ S8 |8 m8 {/ F7 z) G
3 J: S @6 _6 K( e2 Y; d" F
sum ddy2404 R" y. X+ R- g9 D' L
1 p, G9 T# `6 ?$ {# ~0 q if r(min)<0 {: i i, a- I4 ?# @
% T8 J- Z" D6 g6 a5 d7 L
keep if ddy240<=07 s; l" H( n8 ]3 i( G
0 r- I- {. q+ m3 ^) H4 W& z
count
/ U3 h3 q5 s' Y$ g$ z% C
% E* ~& V u, U, _) u if r(N)>2 {+ {1 m; i3 E# s% w* a
: \: s, J- \6 @2 N pkexamine dx240 dy240
$ E! ]0 I2 |1 l( f% A4 \& ` O8 l8 u+ L. B j0 r
local tempminp=r(tomc)5 x8 m7 ]$ v/ }) v
restore " n6 S6 L& h/ s( \( H
}9 I3 H2 U& m% x1 \6 n
! |8 \9 \0 x* n j
else { R! `9 T- `+ A/ r, z4 g
) [7 H' c. _" f* p4 L: \ di "cannot find minp"5 h" ]4 C+ m: A8 ]2 y" T) E
2 i8 y7 p4 e5 M& d, i% Z( ?' S restore
& l, Y6 |0 {( F1 ~1 @ sum dx240) F, J$ ?, {0 I
local tempminp=r(mean): z! Z) i3 m# C" }' B" ]2 u
$ l2 t3 y& @- Y. \9 \4 x# @, E
}# S5 T( e9 B- F, d- S( Z; n0 e3 u
}
5 p4 {* I7 n4 P4 C; W0 e else {
8 C* |& v6 t6 m7 j3 ?- A # M% j/ d2 T9 c2 g. d% @
keep if ddy240<=r(min)# ^' O* z2 F3 O9 |2 J. s
2 ^ h# R9 F" R$ W
sum dx240
8 n( w% H( C) R" o/ N9 ~
3 P3 p/ a# y% L S7 y local tempminp=r(min)% D; M2 w& G/ l' _
restore
, C h6 n4 e @ }
0 H: e: q3 J& P R
- \% e1 I& ?, C- |
1 e( x1 X- J. h- `6 n
! }7 b# Q$ w2 l$ }3 {% w$ @+ F K gen minp=`tempminp' in 1) [3 H1 }8 \* R9 |2 q" y. Z* [
*240 minp
* J# R+ q) f, k* y- Z/ {9 L; O# d# k7 Y; t' X
+ @0 k. N1 ^4 y& a9 A8 t
! h+ }- }5 q+ D3 ]6 j( \5 [ preserve 6 R' s* W5 Z# }8 ^
5 G9 ^7 d% w" M3 m' ~ sum v5 [aw =avol]
5 U* y2 W& c. m( Y. \) p3 m
( ?) r% _6 G: r1 `; i. @ keep if dx240>r(mean)! D' z5 e$ v- ^- T* q# A- V0 d& h
/ D4 r5 \' O" _2 e! R) K sum ddy240
7 [7 K0 X5 ]4 w! _! @, o
2 u p. W6 | D& n V if r(max)>0 {& q5 [8 E. g; h1 q; i
1 f$ z& D' }+ o8 q* J: r5 H9 H7 C
keep if ddy240>=0 X' {6 N: Y: A+ B" _
3 Q7 T( k% I5 x | count2 a" b' u( W9 k+ q, P
( \% z& v8 L' Q7 j
if r(N)>2 {6 J& m' q: g1 {9 G K0 m8 k
8 |4 `2 \2 X$ H8 Q7 ^
pkexamine dx240 dy240
1 F" j+ ?& U* t# g$ E! a; J; k
" A. z5 M* q# v1 m- p/ Z- b local tempmaxp=r(tomc)
) V7 x3 ?& `3 ~" \; s6 O4 [" V restore
3 L4 P- {( r4 T j4 w }
* n4 m9 N# ]7 n/ Q) c2 C% \$ Y
5 I/ v! o$ ]1 [
$ S4 b6 ?: {' a) K0 |" z2 R7 j9 ~ else {" k) Q1 g" j8 V) r
restore 8 O) f( Z: _$ w+ C% i! f
di "cannot find maxp"% g* R; @( H1 b/ @& C
) a$ `. E1 p# D% Q( q1 B
/ S& ~0 l, K5 t! `* W2 p8 b sum dx240
! F3 P4 X/ x& h7 | local tempmaxp=r(mean)0 n% J. n" H+ c- c5 ^' Y# |
! u" N4 f/ I$ W+ @3 h+ M }7 ^! U3 C8 j& p& u9 t
) ?. V; z+ ~4 P3 m- k/ Y$ P0 u& }
}1 D7 R! N$ X+ |& H* V# Y
2 }- ]5 v# @2 F! b5 ^
else {$ c' \0 U6 {6 o$ @4 W
8 k5 U/ T6 d s% r3 p1 R
keep if ddy240>=r(max)
. c, C8 W' \: ], Z # D* a. d0 U) Q$ \
sum dx2409 J' b, S9 @ s& P8 b: g$ [
4 u( ?! Y8 [& ] local tempmaxp=r(max) 1 D7 g4 k! y+ b( r& C/ y' k! u- U+ |1 M
restore * ]( q7 p3 t/ O; ?2 o
}' D9 {1 N$ h: ? t5 R* y
% [) m$ e9 O U' k# J+ }3 c) c
6 m) f" J7 Q% C6 R) W4 S& z
9 ]1 V3 T! i" ? S/ [( t4 a2 W' w# e. J4 `- D1 z' r2 d
gen maxp=`tempmaxp' in 1
& p/ n7 H' n0 M8 z4 k: D+ v' m
# _5 x( m9 S) P+ F/ |, H *240maxp/ q: ^/ g7 g. ?# b1 ]$ B& d, d
+ j1 e6 A( d1 L6 v
8 F) k; {5 B& H
*-------------ddy240pminp左侧高峰值-----. }- w( D6 ]* T! M$ A( s7 ^4 D" _
( ^- J* o$ d1 t) S- X preserve
+ A, f' M) Z: G" I% `
4 l' M e! h$ V; |) j& [+ g9 T keep if dx240<`tempminp'% m: ~0 f. Y, x% E- q3 H' m2 @
E0 q# R. |' @& e. ?% e0 v& N
keep if ddy240>0
% @) m; f8 L" d, V
0 E3 x/ g+ l! c* s count5 q3 G6 Q0 }" p4 _2 `# J# o
% t$ y, L& D8 _' C, T, | if r(N)>2 {
' Q0 b: Y" ^( _3 Y `* [! E
, G: B+ j2 ^! ?/ u5 ]0 g pkexamine dx240 ddy240
- a1 Y6 ^9 \5 m" F : [# p$ j: n' O% v1 p8 Z
local tempminphddy240=r(tomc)
g) y( E' Y" ? restore; L+ m" g! o, b/ P: o
}! u; k2 U2 b. M# s8 @3 e6 M
& h" n/ A4 w G7 R/ l
else {
& q N4 ^1 T0 ~ restore * B! L( L5 s5 x0 W* U! W
di "cannot find pminphddy240"% K+ w, x9 A' o' c, d; O
/ ~7 l7 T( w* [& C# ]- s0 w/ J
$ l+ C9 @- J" m8 Q2 p3 T( C) v sum dx240
/ g7 P: A: c: O8 O. u' L( d; b local tempminphddy240=r(mean) 6 T& P% A b2 p$ {% _4 X" z* q
$ `. y6 J) G& E/ \, G/ z) z+ g# e1 t - p+ ]- J2 ^7 b) F5 \! Y
}
- p3 [! I, A& C# {7 D 8 H" y [6 X7 V& G; A
I# \: k/ F+ b, m: P
1 }; N6 k6 X: T, a& I- V8 p 9 q5 Y# i' y/ z
/ R0 p+ j# O. w# k% x
5 ^3 o3 L7 c1 U" D8 S gen pminphddy240=`tempminphddy240' in 1
$ F, ]) V9 ?/ a; |, c% u& d8 a$ G 5 z; H3 ?% T. b% D2 R
9 @' C: s/ D6 s5 I+ O( t
*-------------ddy240pminp右侧低峰值 -----------------
W1 @& V& m& w4 [ p preserve 0 G" o# c: _! O
7 L/ V- j$ R7 y6 F* R keep if dx240>`tempminp'; k& v) [+ S6 I1 j7 o9 ]( } T9 n+ Z
+ |9 r( T( z" R
keep if dx240<`tempmaxp'' T' D' Y/ f) c" e; g1 S
/ E9 Z! ]& V7 H0 J keep if ddy240<0' I0 k5 \( [1 `# v$ @' n5 ^: f
0 w+ Z$ L* b0 y5 l2 P7 f
gen temddy240=-ddy240
& j) q2 x: @; x: L 0 H0 C5 g$ o2 L1 _$ t$ q$ T
count6 q$ Z$ B3 O* `( a
1 }$ Y& V4 S% Y& `9 q G if r(N)>2 {
+ N6 j9 S: i" \. S- l 6 N8 m1 g3 l1 u$ x: p, }9 R& r2 y
pkexamine dx240 temddy240/ J- w8 y5 |; ~% t' G3 _
7 f9 j" E4 T2 `
local tempminplddy240=r(tomc)
2 C4 F' A" D* m4 D6 k5 [ G, W restore
& H6 I5 N/ ^- |, Y( M b4 J# U0 w }
; p; X) b# V1 B/ w/ B3 H" f
! A$ K& {" X. C0 b! R else {
7 Q8 C1 V7 C& q+ ?4 J# v# A ! i6 B7 k% n4 H2 B q0 p
di "cannot find pminplddy240"' r0 K7 j$ H8 P$ o4 t1 B4 O
restore; a$ W4 Y' o9 |
# z2 j& W. e# G# F6 k
sum dx2402 m8 J: ?: I5 M6 u& ~
local tempminplddy240=r(mean)
6 |' x7 N' e2 P$ D
4 h' G" F+ Y3 ^$ [- i% ?( o; V 3 K6 L$ `" F% o+ u; K [3 A
}
6 P2 w( V8 d' a( F/ h3 {1 }
' e" o z& G7 {1 w1 s4 p ) v: n: z; a1 M: M6 d4 ]( Q
# a$ K# A3 |( T$ v
. u: `4 |' N3 E* g" e- t
/ b t9 d9 E1 p gen pminplddy240=`tempminplddy240' in 1$ B3 b: J% o- y
1 v! d3 P0 o0 M& _( N
*-------------ddy240pmaxp左侧高峰值 -------------------
9 M) H. _& k4 d- p' @ & G2 Y5 g0 H0 C x4 e3 E+ H; W
preserve
9 B7 o% N( F$ @4 {* S 2 r! C$ @. B5 I2 F3 c4 F% p9 N
keep if dx240>`tempminp'7 b4 y( \" E7 y4 \6 A( t
x; D0 ~# }# I3 Z! y# @
keep if dx240<`tempmaxp'; I* ?" i: S N. M* x/ H7 D: D
) }; ?& e1 i. O
keep if ddy240>0# X" p1 M- k$ Z% W) O2 D2 b
count
X/ F7 T3 }0 s. Y4 i
/ d9 M- ^7 @ K/ n# w0 A, A/ m- q if r(N)>2 {5 m& E" y0 M( F5 L
; {: A4 w) A% y" E$ \ n pkexamine dx240 ddy240( \5 s# Q' D6 a" C/ g
7 R3 o) Z( w# V* c local tempmaxphddy240=r(tomc) $ E+ k8 i, v* b5 \6 Z
$ |5 S! u% @5 k v restore
( X* u: G; Y7 f$ O$ b }) z4 q6 R2 v. J* f/ Y) H4 q7 n: M
[! U# F- m" f- L else {
. a9 ? k$ S$ z* y
& D! K1 k8 K0 ^2 D7 I: [: p ]' h di "cannot find pmaxphddy240"
/ }4 Y; x& M# A, G# f( N restore
3 J a5 y6 I* O: B T / K! j4 J1 G8 o* X3 m( \ Y
sum dx240
7 u! h7 K1 u- ~5 `6 _$ a local tempmaxphddy240=r(mean)
/ q+ @( y+ x8 l$ E; w. M
( _& N& B5 t; A9 p5 z 9 a* ]+ N: |. n" z; Q
}
, n; l. S; Y+ E8 G n" L + i8 K3 N1 \* G1 T2 g0 {0 T' o
/ I5 `; q. A$ W5 \
& E: P& ~. F; @* Q9 e( L 9 Q! E$ E9 ^, J" @) p2 o$ D- w# z
3 m+ k( ~0 D3 |0 f3 U" K8 C; v- a5 ]
( C9 L1 d: ?5 c7 D- P
gen pmaxphddy240=`tempmaxphddy240' in 1
5 b1 K2 H+ N: o% |- q# V
( l9 f* K, O6 @/ A4 l# I! \ ; f: b3 [8 d& }1 S, ]7 A
*-------------ddy240pmaxp右侧低峰值 -------------------
6 }+ q% F* J" j7 h 3 D) r9 @5 ^: a9 |' {# }5 I
preserve ( i% I4 D; P* ^: I G/ x2 g
6 }: F$ o; m6 V" f/ e# c
keep if dx240>`tempmaxp'
7 m4 _7 ?" O7 s. t ' a9 P* x1 o5 [2 b
gen temddy240=-ddy240
! I0 q/ D. o! E& s$ T& I6 L
9 f# B. ^5 W1 E5 ?8 \# ]) C# h keep if temddy240>0/ z& M& z( P6 X8 w2 V
$ O6 ]. ?3 a8 ~3 U ` count
' S- P( m- f) l 9 c5 \2 J0 Y0 u; g, i5 F
if r(N)>2 {
) l+ i. h" M: f L& J; h( K
4 L* o5 u1 ~" x8 l: J pkexamine dx240 temddy2406 |$ g- Z+ f0 m. `" Q/ z/ X3 x
0 W( J/ C2 q- f
local tempmaxplddy240=r(tomc)
* P% B6 J3 ?( ?/ E4 @+ u- Q restore
" D G X" @9 H5 { }( ^. V1 Z) {7 h, y4 `2 L
- i4 V4 l9 p6 K6 K
else {7 D* B3 o0 p& L$ u: O# _
restore5 w u% g8 k# ?6 S2 l. k
di "cannot find pmaxlhddy240"8 N. Y9 l7 L+ n
0 w( s2 D/ U, d7 G/ ~- t6 v4 B- O B 8 \+ j+ p2 |- ?& i3 d3 C$ r# o
sum dx240
$ R. h: ~& i5 T4 w local tempmaxplddy240=r(mean) in 13 S1 ^8 o0 w( l$ ]2 B9 _- K
p- ^4 i( D2 Q
# d3 O3 C4 N$ m, {% ~) B; |. E, ~ }; E' U i y/ h
" K9 M+ h, v8 H3 |# w ; a& m; O, d8 z0 {. |
/ A& P U/ q2 D 9 `5 M, {1 s* ?% c- `' e
3 C) `) v% }! t7 A* w 2 w3 b% Z+ I+ H1 r" _
gen pmaxplddy240=`tempmaxphddy240' in 1( j: ?# G+ u9 G6 o3 _ l: S) r% b
' c, S! C; a3 ]2 r$ Z1 t& V
*-------------------------------------
0 w; @* ]( H7 T+ O6 S v- I$ v2 x9 ^
$ R. X6 C' K$ U3 A* B x5 l9 [ gen price5d=v5 in 1/20( s5 t' N9 |7 Q- h" j
" X3 W; ^; @3 P7 B gen price5yy=_n in 1/20* F+ E* p, i, p
7 o( S4 U% {% r3 h gen price5y=price5yy*(dy240max-dy240min)/20
4 a \/ B* J( l7 u, x $ e: r- T# y8 L7 B) E, \- q$ @
*price5y &price5d
4 C B( d0 v! C) X) t 9 v" {& C1 n& a+ Q
gen priceny=price5y in 1$ R' t/ A4 B- a" N2 V$ K8 r
' j! C3 M0 f" v( ^+ N gen pricen=v5 in 1
* j3 [6 z1 S5 e4 J; m6 H7 G3 k% I& m6 Y: R. _" E6 q
8 c, X+ b; ^( o/ Z5 e, z/ P* Q *priceny &pricen
% _0 ]. _, s) i7 I( R/ Q 1 o8 u& V- Q: O9 a7 T7 W" h
, w5 n/ s! |& D2 ~2 o
*-------------------------graph------------------
+ z3 n7 I# {$ c. H 7 ^3 r0 N- V) G0 J( r8 L! g0 G
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)# P9 ]+ x" h$ f
) n6 i3 M4 J" h W' R0 {
* ---------可选项目----------------------( g2 t, Q1 @+ u, S; J7 b( h
*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean))2 r: L! l3 O" j: r
}/ A. c- ^9 f( U) w
end
. [3 A, \0 L+ s |
|