|
maodeng 发表于 2013-1-28 13:13
7 _ I$ k N/ w- h. hello 3002360 c) \9 o* X' @: Z v: }( U
statement out of context' e1 e6 ?. r8 i( a- f
r(119); ' F2 l, a. d2 ?0 C5 @$ F
抱歉,最近太忙了
# M5 I! X( s7 i9 C
# E2 ], P6 e( N& {300236 我用下面的程序试过,没问题6 z$ I. W. x7 e* B/ G& d1 o4 i8 r
4 r1 K. v0 D7 s
你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试
# S: ]% L& i. K) z' ?) N" ~
u2 k0 ~& _) f+ ~capture program drop hello
( U3 V+ o* a# n; W) K
, m4 t: ~) b& j! g5 X8 a3 qprogram hello _5 I$ @# q: G# u1 K: w! z
$ p+ \" C/ N: [; j$ f; L; C quietly {, w, ~: Z+ P z2 M0 n& @
4 x) y" W5 v- V! a
clear; U! a3 y, z) k( D" M7 c" R' A
% R, S1 D* }% j/ \0 G6 }9 Q* `cd D:\stock\test\source
3 H* b6 C# S" X& W: v: @- R1 R" X2 R( |. w( h6 I/ E5 h
insheet using `1'.txt
: }+ n1 C2 ^6 H9 x4 m: t
3 g4 F* |8 J' N) R5 K+ @4 R keep if v5>0
: T9 O6 N2 q- |$ N 4 N. m+ j6 {( N& m8 b: Z+ p
gen vt=_n
4 H: S3 @ Y+ q$ N/ k
3 d+ M/ z( E0 \7 d tsset vt
' R' O" }0 Y0 X- O2 e* G6 C# @% z G5 M2 C
gen zf=D1.v5
) _, r+ H- f7 f: N
! {+ t0 x% U5 f6 y [# F gsort -v1, C7 A* D. k0 [4 w d
" ~( u/ D- n( [* K gen avol=v7/v5
# U2 `( C! [- \$ [4 E( e- Y & |/ \( \- [* F% M: H
keep if avol>0
& m# }8 P/ \" T) U% m : H7 W |% H' B$ T8 ]& \$ U/ R
drop vt
& h, G- c5 z& a6 _- C7 b6 \# i
! l6 V, p& h7 {3 Q5 Z gen vt=_n
0 h+ [2 V6 L# `1 N' w9 [
7 v8 x% |7 |$ F/ ^* @8 M) q tsset vt
$ E# `8 l' b# |0 C# T# W
! L( X/ h0 S7 e8 p0 R6 J sum v5 [aw =avol]" X( c% E3 O4 j2 ? ]6 o
" K- V% X% w M) A4 K
gen amean=r(mean) in 1
+ |, q. [( {: } |
2 X# B* P7 b5 C% D' L * 总加权平均值 amean
+ d" p2 y. `. B$ n
}4 J1 ]& M8 A8 h
4 A$ D" a( h; \ I, E* { keep in 1/2400 y2 L6 u: [: l; v) c
8 c% L& {0 C }. a6 E: B sum v5 [aw =avol]
( [7 w9 @" ^1 s' S: g. {. \) O3 i1 n! n6 _4 E ^+ N
gen mean240=r(mean) in 1+ @- X' W) B4 u; v( ~
" [* a$ r! X( F. O' j *240加权平均值 mean240
0 p0 I7 D3 `9 z4 D% l; o- s1 X - t* a/ j( l- A# w: m) W0 v
set obs 500 3 b5 C M8 L3 t+ `5 {) ]
9 h& U, `2 l6 r
kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
7 m% i3 M' \% I& X$ H# [
" F( o# G X; w- b) C* | *240 kdensity(dx240 dy240)& y8 o, z9 Z8 ]! t! o) k) Z! {* [6 K
/ M- \7 X# g6 u5 P sum dy2403 G; c0 w5 q9 P, D" u! O
" T5 P4 B% r5 N* w$ C, v
gen yxis=r(max) in 1- N& y/ W: B! H! F7 p# y( d$ T
- K, y7 j+ E8 Q8 f6 R gen yxis2=yxis/2) x% z+ Y t v4 Q& J; y
! g# l$ O; L" F/ s( S *yxis7 x' I( _, I3 F+ _ L2 Z6 h
. B2 F5 c6 c7 z gen dy240max=r(max)# A9 Z9 D) b1 J2 C
- A, v5 [# W P! S: [ gen dy240minp=r(min)( s0 g ?2 M/ t$ b- b3 A2 h9 r
( z1 b+ H# Q9 h7 v0 o. d gen vtt=_n4 a Y2 Z, }; p5 z( D
- v$ Q+ b& k, u' y# ^0 Y) ` S
tsset vtt
' B6 F u- u* U! Z
4 i5 c7 l; ?8 Q- S L. d2 _* j gen ddy240=D1.dy240/D1.dx240$ z5 }% }( Y) T) g
& T% K; y# l, C! D( j+ } sum ddy240
+ I/ Q. o$ m: z$ I" j7 h
# b8 {1 J P; J4 J% S: p gen ddy240max=r(max)
d4 h: J% d5 \$ o I
B% ]8 Y- e8 ^ L$ A0 K gen ddy240min=r(min)
1 B q: | i* P! P0 H 0 J" _5 j+ K+ Z
gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
) { f/ E- d; l0 G" K! a. y I3 ]6 \& l5 `. W1 U
sum ddy240g0 O2 H# L0 o; B! g* c' F
8 F- A$ Z! f* j8 U, G& V
gen yxis3=r(min) in 1: t# m& i0 E: E k( c8 E
. s# [ J* q! N4 W3 q3 H# H6 b gen yxis4=0 in 1
B* w& L6 J' k- { 3 d. J# V. H- Y: h: [1 G
*ddy240g # R# Z. T6 Z. o+ {% S, B
d2 ^5 D" t0 i" l- W1 H
v* l7 i+ H# O. e" W' f preserve
) }/ |% {& L4 D
4 |& X/ C( E2 B sum v5 [aw =avol]
5 f/ I8 M0 H3 C1 n 1 _9 ?8 {, p' v6 x) A
keep if dx240<r(mean)7 x3 Z* z' o2 Q8 y, n, d* A. E7 R
& N1 m7 V2 y4 \0 K7 ?5 e
sum ddy2407 `* Q3 T# ^- j* I- r0 T i
9 ]+ K/ S' u5 U8 d" f9 s* g if r(min)<0 {, N7 p% Q9 _7 ~+ O
5 @1 e) C E' o% P/ U keep if ddy240<=0, X$ n# h j, F6 l
$ ]9 `' u' t1 L6 @# x: Q2 e5 o
count
+ _: H+ k# v# z( b2 c& G ' I: N8 P$ P# Y, D
if r(N)>2 {
" e" a* D Z9 f5 P- h ( {; s1 u5 M4 h. x2 Z
pkexamine dx240 dy240
2 U* Q }9 E0 e" F1 N7 q 8 A/ v8 n/ p/ j0 P0 \4 @
local tempminp=r(tomc)* m# u/ K/ i( t% b1 o) n
restore S1 ]3 K% a7 y ]
}
6 }7 G3 G- F5 i0 O
K/ E7 ^; y; a, _ else {
3 O' D/ e7 u- V( M3 u. R9 O 7 }7 y$ |7 K! i" e5 W: c, Y
di "cannot find minp"
, x) ?- Q, p8 `) c' _6 E1 Q
, {5 n$ X1 N" A# Z5 v; F9 Y restore , M( B. s# B6 _; m' t# Y5 ~7 z
sum dx2401 n7 H" f5 Q( y5 b
local tempminp=r(mean)
" t7 h5 D7 F" \/ Y/ r; U( ^ ) k: S. i) e% f0 j9 X: J' _4 `
}
* B% o) M& T5 S# j+ l3 R }. ^+ f8 K5 f. i2 p
else {) Z$ b0 J2 `0 B2 J6 w
& [7 g# P. b( S6 X keep if ddy240<=r(min)* X( a( R" X" p: r
6 V: b$ y. j( ~ sum dx240 B. c J7 Q8 s! w
! p( o* M: \& E4 e+ j% ^- ` local tempminp=r(min)9 |5 t8 y$ c! o- [$ R' r. ^' Z
restore
. ~7 B; q# r" }9 o0 T/ ] }
( K1 [4 X9 U# U) J* Y9 i& L7 Z5 w( S- N8 ?
( R- k6 Q* J) y6 k* F: g
, ?2 z; [1 }. A; M gen minp=`tempminp' in 1
/ J8 m* A, l0 A* {4 M+ |% F$ j; T) I *240 minp5 f& _ J6 n; z7 G) g/ ^ @* H+ l
8 H* W3 I/ [0 _2 l: R6 @% u# a! y5 ]+ c+ u
( D: |% c( d* C3 A3 q% z2 \ preserve
# C; a% c2 ~& J8 p& u# z7 V
. X# c' k- [8 q) { sum v5 [aw =avol]; d$ L& Q* C0 x% U: o9 G
# O. J8 S+ f8 C6 l
keep if dx240>r(mean)& u) s- O$ _6 G
6 n( J% W, G0 q- m9 _ sum ddy240# x; l s/ V% L/ P. K/ |
4 m: n) e+ F' P5 s if r(max)>0 {
2 |0 w _1 w7 w1 A. a4 w
! T/ S; U4 B* t# Y0 l, t: L. H: ^ keep if ddy240>=0
# h. |, v. O, R( `: F! `5 }& w
. s9 t' E" ?8 x8 Y5 _ count5 Q" i: W1 M) f6 B# Q
7 l6 a! ?& ~3 a" {, {
if r(N)>2 {
* C( ^8 O6 j/ T) ^0 j8 O/ F- X
) f! C9 T8 n- I! Q: r pkexamine dx240 dy240" x* i: A, f( Z0 z$ |
! b8 a- K( ~1 n+ o! O. A
local tempmaxp=r(tomc) 4 ?2 h" m* L1 E5 O7 i. k3 ]
restore S o$ T+ n, v4 M) F5 C. a
}2 b2 R. v/ |2 U K6 n9 G
* n7 U4 b( H; V) K( Q1 Z
+ O+ R+ f2 F I- K+ T- T9 } else { J9 a) U# h' G$ \. Z$ c# Z, j
restore
) u( s6 J0 m6 Z- s7 _4 G2 o di "cannot find maxp"
* ~, h3 x* N6 Q& ^. i. U" [
& `2 A0 U# V' ~# f4 J5 E6 f, ~4 r3 C, f 4 m( x1 T: T" ~+ S
sum dx2400 J( P! ~4 e0 o" ~( O5 q# Y
local tempmaxp=r(mean)0 \, r- |* x; N1 U, L
3 z; J0 a7 j/ k( ~6 l; M
}0 f( C/ N& x7 F/ o; }
, o: d$ L6 p8 i6 m4 k9 X" i; M }3 K0 {- I: k, [1 O0 O
: t" i, o* w% [- d else {! E- N- z% J* ~' E2 P# W( ]
+ h7 b3 _# L' K1 _2 w# D keep if ddy240>=r(max)" f k, j# |0 D3 }5 T. l& C
% \2 O, [1 j9 `* t1 l sum dx240: ?, i8 a T) }% N0 h q3 B) `
2 Y/ m" \7 }9 j9 r$ J. t
local tempmaxp=r(max) 8 [+ q7 R) m3 `# D: i/ X# B
restore
& T3 A& r% p' N9 i }5 ^0 [5 N$ G h- [2 c8 T5 x6 \. d
% `8 M4 _7 W- ]. {& L; A9 {' t6 n
3 D+ n6 C- k+ |8 H' E6 s" M
' \$ }" a- B* l" L9 Y4 v5 K gen maxp=`tempmaxp' in 1( p. e8 ?% U5 k$ e
% s2 s/ B3 q, V% g! K/ N" v; W2 W
*240maxp8 q5 h7 w! `, d( p9 E% x
" E/ X ~. Z3 d
7 V) c# f4 W: x% @8 V) M1 `( M *-------------ddy240pminp左侧高峰值-----( ]9 Z1 s q2 c3 C
+ G4 c. o( E% L$ n) ?% r preserve + T4 h9 f! g, X& B& F( K
6 n( y' r0 |2 ]$ x( u- W
keep if dx240<`tempminp') Q8 [5 E8 C8 H2 W5 v' m
6 \4 b, C5 \0 R; b( ]
keep if ddy240>0) A7 x) K2 E) s" U. w* ?
: J) ?* R. T% K- k3 d
count7 y9 c& \* G0 P' Y* {
, m: n; u$ b7 X5 Y- H" f: x if r(N)>2 {( x; @5 _" b8 n' W1 x) g8 g. O
* K5 z* a e! q8 d* w. K5 [
pkexamine dx240 ddy240$ ?- o6 n- Y; D, t
0 Y4 y3 n% ~. F' {3 C local tempminphddy240=r(tomc)
- ~, Q: u# s, U) b6 Y5 K7 ? restore6 @+ Z, F( V+ G
}
5 f6 a# o0 g. @5 K + P; ~0 e/ j$ T. l
else {
- x8 r+ `$ ~* w5 V: x restore
+ _& ^2 ^/ h$ O! l) o7 k di "cannot find pminphddy240"
0 G% E* [& Y& G9 L' _- J; H9 N / a. {* m* {3 L) [& a8 ?- z1 ]1 _+ f
8 B. D' y, r) t& h+ N sum dx240
. F9 Z$ e7 o6 ]+ n# z) Y& H local tempminphddy240=r(mean)
$ `) h: i+ }: q& g, ? ( i$ ]& g, i% S% j! `' ^
7 P5 y# U/ V" \7 g4 ]! p* V
}2 t6 Q& \- |7 h9 a; W" Z
4 x4 l0 D! J' a3 W8 S
5 d# }/ G. H+ K6 a8 l2 Z6 v 4 Y5 k1 R. ^1 z6 J5 A. O
: ^* U$ x/ }1 h g3 Q7 \: k
, ?! n- t. f5 T8 a1 l& I
6 o4 k0 b! t* b
gen pminphddy240=`tempminphddy240' in 1
% y7 d- R/ U# J' }. s
9 z9 I4 O' |, E( @
' E# E( U0 O0 W% [ h *-------------ddy240pminp右侧低峰值 -----------------8 }% T# R1 L, A6 O
preserve
! t/ O! ?; t' i/ s
$ C; [+ d [/ ~5 M( g& V2 ~( _ keep if dx240>`tempminp'% }' b% w1 S) T E8 e1 _1 b2 y5 s
- z7 v' I$ m* a
keep if dx240<`tempmaxp'/ ?# b5 j( X$ P) O
Q, [4 f- D2 h- \% u
keep if ddy240<0( ]9 |6 H8 V$ i2 A% X) h
' |. V5 v2 G9 W( X
gen temddy240=-ddy240, e, c! C7 u' l
# F3 z8 g' a) W/ t8 |8 a
count: f5 m2 C# V1 v
( D6 N S3 M& X! c if r(N)>2 {
8 a$ e9 X: g1 D% L( q
4 k9 L& A0 Y" J, p pkexamine dx240 temddy2402 I5 W5 t/ k0 F6 z" @0 i& c
- ?" r) B7 Z+ k( q w( I* F5 [
local tempminplddy240=r(tomc)/ e- W/ I% u9 o/ Q% z# q: E
restore: C: @6 L; G+ ^! ~3 W6 m
}/ l6 B0 O' o% [" }) r4 T
& h& H! n/ t: U# D3 _ else {
1 g8 ]# o4 M$ o1 W2 n' K. S# r$ j 4 }' O. X0 C( P" }
di "cannot find pminplddy240"
5 [1 W, R& i* @& K% G9 X6 c2 u restore3 J5 J1 a3 L$ x8 @
& V1 e' D8 ~8 j& H5 B& X. A5 l
sum dx2404 u$ o0 |# J1 u2 e9 G) P& d) j
local tempminplddy240=r(mean)% ^0 q' e) p& X. B
2 `5 `) \( f% \& e5 E h/ ?9 v 2 a$ l) J1 H$ J' ]( H
}
( d9 p# P- G# E' l- I& o
1 k& H5 K' {# g1 t" v- F$ _. d2 I
, f* J$ F2 m& \4 B& b% p 4 A+ ~ S5 d9 R! Y. @, h
9 f0 J: V$ S& Q: \2 r" p $ N5 B2 a2 e$ U6 ]
gen pminplddy240=`tempminplddy240' in 19 E+ t% o8 b X; ]) n2 v
9 Z) V9 ^: E! h *-------------ddy240pmaxp左侧高峰值 -------------------8 L. t% ]5 w8 ~& ` Q
/ C( _7 T- Z6 G
preserve 7 _; q) K% a4 m' y6 T* f7 W7 \
" t7 K% B) Y2 o( @, s, I9 y* Q
keep if dx240>`tempminp'
}6 O8 J; ~) w) _. g
3 T- b3 b. C r5 O keep if dx240<`tempmaxp'
' X9 q2 N0 B+ `5 \9 g. P4 T2 I ' e# V! m M3 l9 j/ x9 x5 j
keep if ddy240>0
2 \. E# Z* n3 T- O count9 n, o- ^# F4 d" c$ l
! g& q: Q5 M' d6 i if r(N)>2 {! ~9 E' W/ C$ b7 P7 R ~
2 @% l* q" _/ _7 S" q1 T' K pkexamine dx240 ddy2401 G) _6 e5 W! \1 ^5 k: U2 B, W# V/ |
$ a% D, ?/ O* K& f) U
local tempmaxphddy240=r(tomc)
& }% Z2 m# F( `$ m2 F % N9 z% p0 H; D
restore8 L" ^/ E5 g2 O9 ? X
}+ G# Y/ ?. }/ u" g4 F6 k
3 q4 Z6 ]! k9 I! N; Y& E
else {
- d: g. h* z3 L- m. O6 o" T
, S- [4 _/ s# s4 w9 D di "cannot find pmaxphddy240". s: q0 U# ~* \
restore
1 e% k5 I9 \, P' i- d$ M- r0 z & }0 Q* k. f2 p9 q: S% ]- ?
sum dx240
1 A/ O4 ~' S2 S- ~; b local tempmaxphddy240=r(mean)
: Q' o+ D# t' O( k% |" w( U1 q ' F' e0 _; ~' e9 r+ |" b8 b
6 a2 i2 s$ @1 V% \! I( w
}8 f: Q L/ L, `7 U& G# Y
3 w B' }) P5 r& K & f! w! H+ Q% u0 l
! q2 q T2 m$ t; o* {
4 m) {, D5 [+ e" y, f4 m
3 C) y; @/ q; Q. D8 w
& W! H; _* A+ K gen pmaxphddy240=`tempmaxphddy240' in 16 ? Y. F& J& W- J. A' k, m
: `5 g( s2 i4 W8 u$ r: n ) g) v1 D+ L1 |' t1 d- U7 U
*-------------ddy240pmaxp右侧低峰值 -------------------
. w% U4 T- B' \* H* H" { y
* {* i3 f+ K3 [% \2 H9 e' m preserve
5 ]: t# s1 p0 v' `& j3 [ 4 r# j& D6 d* ~* x. B" }5 O
keep if dx240>`tempmaxp'
8 W1 Y. O. C" D/ H; B; r
9 x& [$ q: e. L2 ?% A7 ~8 `% \1 | gen temddy240=-ddy240
. q' C& C3 C: `! Q+ o& c; h ' U: |. L- R1 Z2 n+ H/ v7 `
keep if temddy240>08 x4 Z& o0 M" O2 _$ Y+ M+ K
3 ~/ g7 O; x: z- A0 l( E; E
count2 t H$ N5 O* i R7 `$ E7 O
7 Q! ~9 {& `! p9 V
if r(N)>2 {
' ~! ?1 Y- O9 a. C- u8 x; ] F ! g& e4 g p( R0 \ J
pkexamine dx240 temddy240
- x* {9 B8 B- O/ G5 O0 ] * |5 I6 j4 ~, n- X/ X8 }
local tempmaxplddy240=r(tomc) % z. m2 w# [1 e
restore s( y. W ~' E$ f, S
}) ^8 [5 Z$ u& |
5 u6 A# G% \% p8 K- \
else {
+ H( Q6 r" t4 ]& S7 e0 z restore% R( K. h/ m0 _- V; w
di "cannot find pmaxlhddy240"
2 \. e2 C1 g! l3 o + Y4 g7 b# f/ ~+ ?/ X8 p; {) B
6 f9 j V& ^" ^9 |0 s" h sum dx240, K) c# o4 Y; h& ^; y3 {
local tempmaxplddy240=r(mean) in 1/ q4 c" G0 Q8 h2 m* Y
- B! t+ k* G1 X1 q& j) K, {
1 P( A" f# F8 W8 `: a
}6 y+ a0 B' U+ {- ] v
' T( d+ K' K4 M* k. c: [' j5 i
: r* y! G# k+ l: h+ L, s/ v, d( u 5 ]1 X0 `! U5 ?
( Q1 r4 ~/ N& Y) W* V! W: s3 V' S 5 ^; U e. l% \1 u/ @# J
- O2 I: y" u, V) F4 N- U
gen pmaxplddy240=`tempmaxphddy240' in 1
2 Y- M( h! W8 S. P( V
( k2 M& I0 U5 e# @" g *-------------------------------------. Y; L9 h3 m7 H. i' s% l
% p& O* I0 U' d+ K gen price5d=v5 in 1/20
1 i2 I& ]7 C' O* [: y- P
3 M7 n* l1 ]3 Y, j6 i& i6 d3 ]2 y2 Y gen price5yy=_n in 1/20
+ ^" ~% ~, ^! C2 f4 Z
4 I3 Y5 T3 d$ F) n$ D9 }8 _ gen price5y=price5yy*(dy240max-dy240min)/20- i2 G; U: J& a3 f' J! b/ Y8 p
& k* P1 `' u* `2 l# `1 Z6 H *price5y &price5d
/ \8 ?1 U3 I% p# m$ F7 c
2 i! Q! T! N p' U, N gen priceny=price5y in 1$ f4 e. a/ K+ g9 N
$ Y0 L5 e( l* q" i9 A gen pricen=v5 in 1
% h2 s4 K$ Z! i$ z- n/ H' n v. M; L# J1 O8 ] y
& ~/ G8 m8 g# g0 u+ S. X' Y
*priceny &pricen% g- n% T3 O" A0 w
" z+ U9 R. Z1 F) K
& L; W3 {* d2 h$ i7 c
*-------------------------graph------------------
8 c+ \7 }+ M( Q" t) H. u t , x+ N1 W1 l4 a1 @0 l( n5 O2 I
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)
- i2 `2 C0 q0 s% l2 k6 A" M/ N1 g
\7 Z& q# \1 v' s5 ~( @* g3 A* ---------可选项目----------------------
" F- D0 E# @% l5 v*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean))
( a2 r: v" A3 a! }3 M2 l}
' j: C7 f1 J0 `( z) `end
8 N8 W5 u* {- [! J& a# E |
|