|
maodeng 发表于 2013-1-28 13:13
, _$ \' q# b: r N. hello 3002366 P( k" N/ g( [8 m: j& j' b& O+ O
statement out of context
; c0 N( g3 }5 l4 j6 f& L- p0 |! pr(119);
2 l2 [' Y% S; W' x, @抱歉,最近太忙了+ L/ s3 W, E. b# l# ^
. J4 E: g& d" }6 E0 }300236 我用下面的程序试过,没问题6 f8 ]$ b) w& Z9 Y E
, D% M$ w5 M* |) J, P" X+ f0 O你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试
" a' ]! L+ {1 }* Y3 a
# O. r6 C; q8 y# e2 b `! g( O7 L: Mcapture program drop hello
$ j. t7 q- i* P* J) |" H& ?8 B* s8 e
$ ?7 x6 l T, Zprogram hello( e- r$ c" w9 R# [8 r& k
! O- V- X- i" B quietly {
6 v! e3 d6 P( i5 E: z
' ~9 n; E) e8 F2 o2 gclear
- u G! A% b+ A
4 P2 F# k( K8 bcd D:\stock\test\source& B, H3 H- y1 r+ a; D1 V+ p: D
2 @8 t9 D5 t& l( Xinsheet using `1'.txt- z- l' D4 ?, ~% W/ `
% C% `) D7 ?- @2 L$ W
keep if v5>0
" u) I; J6 |* _6 [ 8 m& n% u% W" h4 w! \% A
gen vt=_n4 R4 t+ o+ Q' {4 f/ w5 F% `' w
/ ~, S% c& c3 I& V" c0 P( D
tsset vt! x$ P) ?; O0 m6 P8 O9 R* f; e
+ a. ~. Y( |+ Q9 s
gen zf=D1.v5/ A: n& ^* M( _9 Q' y, {" D5 M8 F
0 ]! b8 ^( G0 a, ` gsort -v1: T* K% t+ C% C; [1 q& B& Y" {
$ U7 Z6 v8 d9 J* ~) G gen avol=v7/v5
% H' U) Z) R l' H5 ~
) T9 J8 B* ]4 h9 R Y4 S keep if avol>0
# g1 q, i. J8 v/ s6 a , \1 _4 e$ l4 r- Y! ?2 z
drop vt" S4 S( s' q9 \6 [
: b2 p; N9 F: T6 o' R: Q6 D
gen vt=_n
$ g' _, w$ [. n, U+ {; [ & t+ |- K, v4 I
tsset vt
/ }. a1 F2 _9 [; j- E% z" h 7 ]+ O* P& Z& u+ z. w+ O/ b
sum v5 [aw =avol]
& O- w1 a! E/ y
) `7 ^( r! D& f8 q gen amean=r(mean) in 1
/ O) O2 ]' n. k/ | # r0 y* P) W% a. p* P6 s4 A1 j @5 p
* 总加权平均值 amean8 l# m7 I# c5 l% j8 u
4 S3 L: `% a1 U$ `- j- J: N
) c0 c- \0 d( \/ b6 J keep in 1/2400 F# k: F+ e$ F+ ]. y" i0 s
6 K( r- _9 r Q. M! C! c5 {6 F0 G sum v5 [aw =avol]6 j# ]7 G- q7 G B+ b
6 g1 F- L, k# r1 ~6 G gen mean240=r(mean) in 16 O* B7 T+ h W% J- P
2 t7 l4 j5 y, p! R5 b2 g *240加权平均值 mean2408 f% c7 d) h( D# q
" N. \7 W) n- [
set obs 500
9 a& O. o- q' X; w; q2 [2 _4 U% P; s
7 }8 S& F1 `* r6 g f kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
; I& _$ d$ n$ p; I# T7 e. j% \
9 S$ N+ q# e* x; W3 v( l. B *240 kdensity(dx240 dy240)
7 L( F2 q" a0 E( T
0 {9 Q9 r+ k( ~3 H" u3 J% s sum dy240# V) [/ j: O: E N
& m; I1 w4 d& d" c7 W( D! U, j
gen yxis=r(max) in 1
! Y8 p+ `& o- W+ ]7 |% f ( Z% v6 ]( q' L4 {: D D9 q! V
gen yxis2=yxis/25 N+ W. D! \( ?& Y: Q
* V7 i8 d# P2 L) H
*yxis
+ [9 o0 ~9 N/ M' M$ R ~ 5 u9 m4 q0 a- D9 W7 u" n& M4 J
gen dy240max=r(max)8 ~) T; S O- Q, b5 c) C" H; o) @) I
8 i8 a4 ]( N9 p0 C( g, r& R" Q
gen dy240minp=r(min)- E( x' d: q2 a J) v; `7 }( C# V
, N3 N, G. ]4 ?* I. | gen vtt=_n' s% b7 x7 A. I( c2 }- D% V, Y
( n# F& E7 _9 p' y3 i4 @) Z tsset vtt' ]( h2 g% _9 q% I0 b7 m
0 C7 h. u' |7 P8 c
gen ddy240=D1.dy240/D1.dx240% T% g- v1 r9 d O* }; V& d
{# a3 E" @' Y& v. w0 F sum ddy240
, D w9 p1 u; e3 j E! { 0 T1 d9 J; M9 s8 j" F) V% c6 x, i) u: D7 o
gen ddy240max=r(max)9 q0 [' e. V$ a% {
# O% x- p2 }$ @' E4 f gen ddy240min=r(min)" W4 r# K' J& |, N1 y
! [/ o; X. q, |1 k% n% u
gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
+ `- O* M$ ^1 d+ `! t- O. o + `, {. G% e- }
sum ddy240g) X- Z$ v1 [0 W: |, ]& x! }1 }
! s% \, y8 Y! F+ ]: c9 j: [1 V gen yxis3=r(min) in 14 t7 |7 a/ y s- k
4 y8 t0 N- `3 O2 E/ Y gen yxis4=0 in 1% l- j! ^# X$ z& o. f8 s
! G' J; `9 Z6 T8 d2 f+ O/ B
*ddy240g
/ y6 ~# ]% X4 x7 a" W 3 m% Q$ b( o5 m- {0 o2 Q
# s# R2 V$ e V& x" O, A2 P preserve " U6 ~& p6 F7 ~2 x: D8 Q" c# T
6 ^ B$ K; V6 q( }. c
sum v5 [aw =avol]
. b6 |, C% u' \2 ]8 i b' M i) ^ S+ ^$ x# X9 k
keep if dx240<r(mean)' P* d* e/ ^ g/ x% ]8 i( u
# v7 t! f$ V& B( W3 x
sum ddy240
8 z! ~6 h0 v7 r5 K$ J/ }" _
! l1 A' ^) f6 X if r(min)<0 {
9 |# x0 d4 Q, q, T2 ~
, {: V* F) k: X$ v4 v: b keep if ddy240<=01 ?6 w: Y8 A3 c1 ` l) n/ t# y( X9 @
; `( I( e" S) _" U count
* ~! \+ J: o* r/ j& I; m6 L! I
1 m- A4 h# B% M, v: Z if r(N)>2 {
$ K/ y. T6 G6 A# p7 c9 W6 O 1 E! _' M3 u3 E2 I4 R
pkexamine dx240 dy2404 d' x9 j6 b4 @/ x
( G0 z$ k; Y! P4 `$ ?
local tempminp=r(tomc)2 U" D7 P5 Y0 V$ [& T4 \
restore
7 e: I/ ~3 m+ N$ q3 G }: y7 W0 O- T I W0 ?& C# J
+ \# m! x, \; Z7 A% S. `
else {
" L7 M; ~, P1 U7 S5 K ) s1 D! x! t. F) n7 Q$ g( y j
di "cannot find minp"
; b6 v; M8 k: V/ R! c( T' e
/ B% M% ]4 }/ e- A: S restore
% ?. @1 }/ U( w8 c/ ?( C sum dx2400 D# R3 b. h' m" m$ A
local tempminp=r(mean)
/ Y" u4 \% V/ L+ c # w' t7 V6 {8 j' w; U
}! t. q3 C# n$ w; p4 s
}9 S5 b! V! U8 T' p$ p
else {7 f4 c ]3 N" k; Y9 O t. k
) E) l( ^1 f6 b keep if ddy240<=r(min)
# I* `6 `6 I% ]* `$ Z 1 i$ W2 r# U+ v' J
sum dx240& a; n( x0 J. Z! _, A
p$ `( i& P* l# T5 c
local tempminp=r(min)' V8 [( b6 O, b$ H8 D# B
restore
, q* w3 E! I; H) G }
- z, B- q# I5 S+ ? |) _
; ` |. S) Y, p/ |9 \) W9 d. V, ]6 i* y
9 J6 X$ ^! D4 K5 k0 H gen minp=`tempminp' in 1
: d3 ?: k9 R1 g5 p8 f& o( r q *240 minp! T. M" c- s p" N8 Y1 d
( Z+ `8 W9 e |1 P+ ^% G
5 o4 c- ^$ y3 l9 | ( l& P) Y7 i+ S
preserve
) }* G4 j% g- g4 e/ P
2 {" H4 W# z& L; ?) L% m$ {& R sum v5 [aw =avol]( y$ Z9 ^5 _9 r: Y" D2 }) g
. v0 O8 j7 r4 h% a0 L' h
keep if dx240>r(mean)
7 d4 q! O* U; C+ F6 a4 X* V# L
" M8 Z7 C2 w2 O7 w0 L! J- G: Q sum ddy240
; S/ Y$ X3 D# G9 s8 V , ?& e: \0 G, \6 G) H$ z
if r(max)>0 {' Z) |7 v C) b6 x t3 y
9 q6 f2 Q: ]2 m* [
keep if ddy240>=07 p9 R t5 V4 K& s4 Z# l
$ J& \. ]! U, E) c count) n/ Q) b5 O+ d
+ Z3 F+ _7 `9 A9 c if r(N)>2 {
8 h' K+ g% n+ z$ F& c$ L; [ 8 f$ H, w9 Z4 L% B1 z
pkexamine dx240 dy240+ @) g5 z5 t$ O% P9 D/ } r/ a- \
4 R, }7 ^, t$ D' d8 |; p8 U
local tempmaxp=r(tomc) ( h9 w$ H/ b, b# P
restore
/ s. b% H( b+ [0 t+ t }6 ] ?2 v- d1 R, S* _3 y2 Y9 X: G
5 K {0 r7 o4 a
( H- ~5 R4 ~0 a4 A else {
5 L! a& c# ?) T% [ restore
8 M3 Q% C: S; k o1 I di "cannot find maxp"
, L5 R X! ~6 E! c
* L3 L6 R& b- H0 V , G8 V% g9 X" r+ P# m
sum dx240- z2 s; f# x9 s
local tempmaxp=r(mean)7 O/ X# n7 K0 J' Q
8 B9 y8 `4 P- J: q3 A# ]" M4 G( S }
* D3 x5 `3 D0 k) W: S$ G! {* m
* M; x% ^# N d }+ r* c( m, H8 _. ?0 t. c5 q
" j- A8 j# V0 y- W, S else { S/ Y1 J3 q# f- b; P
3 j* r0 l/ E* l- { u% z% R keep if ddy240>=r(max)4 f3 S9 Q; i* u) O$ j( b
( u8 {; U( C3 Q' A: [
sum dx240
& I; s" b* H% v% A! v% f% u: G" e 0 z# [6 @! s0 b# B: h
local tempmaxp=r(max) & l) A5 g6 `6 U" b
restore # b, \& u3 S3 k& \
}8 E$ S1 v! a3 E
" T, y. v0 Y0 X; J! o' M: r, {# z
5 b& h( L: v, l6 m7 H% |
! _/ i, A7 ]- E8 i" U8 d
) ?1 J9 ]" I/ R: d6 n1 u* d
gen maxp=`tempmaxp' in 1
8 D' f. o3 \, W: y; o c* x, U ' @+ s8 U9 f- Z; \
*240maxp: O; C, Z+ ~9 S/ h4 D
1 g2 k/ x( S- i7 s/ M) F6 t3 T# @
$ ?& L L9 s8 D) e# z *-------------ddy240pminp左侧高峰值-----
^% B8 S' |# v! s# A
0 z0 p2 H4 T; A( L: q preserve
! x8 A) O7 `" y$ ^# ] - d6 E" P3 x9 W7 \( T
keep if dx240<`tempminp'
3 X/ T3 f' `7 M+ B
8 `. v, y* @# F keep if ddy240>0
* b6 \/ P. B2 k: G+ J# n6 F( D# [; P9 z 8 L% Q# u! {3 }
count6 e! g! B% X) L, r1 r8 `
3 R; t9 Z; f% `: Z K if r(N)>2 {5 g2 y0 a( T, K1 k! `
0 x. p4 L* Y2 |2 I) x5 ]8 V! h; n pkexamine dx240 ddy240
) b5 F' _* `" r6 k8 g 9 p# C d7 _1 l1 [4 g
local tempminphddy240=r(tomc) " s& _' J0 H: r
restore* U6 I/ L7 A: P+ [5 K4 ~) G1 M& }
}+ ]' f8 S* `2 O" j% Q: O
7 `2 _: K) {' T* g1 \0 l' i; o else {
# r% s& e3 p& \* ]$ t restore
2 `8 ?. h H0 P& ? di "cannot find pminphddy240"4 f+ d; p6 O' z) ? T8 F9 I
" y5 k; O! U0 f/ p K : o0 a( h" S+ H
sum dx240
2 p9 ?& O" D8 { local tempminphddy240=r(mean) T% |# Z5 H. t" Z' H2 U+ w
" t) d" O0 y9 h! v* F9 m. D: ^ 1 h# a7 D% O m" [$ I' O
}
& |* _ t6 p2 }2 y % J) [( c7 l) b
' A# P7 K" ?' x % X. l% ?6 N0 [; j, U0 N8 i4 t0 f2 a+ r
# G8 Z( [' q$ l* x. r
9 D2 q* e) ?2 E _, M
: w4 F3 K' a7 \, f8 g7 u gen pminphddy240=`tempminphddy240' in 1
! t7 v I. `# m. Z
* g: U& A8 b) ]- t 1 U- x. v! d3 m* ?, N
*-------------ddy240pminp右侧低峰值 -----------------
6 `0 S# L/ Z( ^# W. R preserve 1 f$ X+ Z- S6 c9 n/ b
3 \" f2 I5 B/ M8 Z. x( b6 V keep if dx240>`tempminp'
/ N0 B* J% c" |& V6 D8 E5 b+ d, M( l
# |+ S/ ~; ~# C( o6 C* Y keep if dx240<`tempmaxp'
/ s6 L. I9 @0 [! S2 ]# N ; z" W1 \ \- H* c' m! D9 I2 b6 H s
keep if ddy240<02 E; @& O+ E' T! P- Q# i
9 Y/ U9 X( r9 K! O- S3 C y8 y gen temddy240=-ddy240) g/ V3 O. U- g
* S) s% }8 D; }& k' W' w# r0 W count! z, y, P) T& l' v& E9 j9 L
' p4 V; O( C0 G if r(N)>2 {
! H+ W y) c) J; }
( [ T( N6 [: `( h1 }1 R9 w7 L pkexamine dx240 temddy240
/ u; `9 Y/ e' P# {, Y: a 6 t0 c6 r9 A$ ^7 W8 E; y% A
local tempminplddy240=r(tomc)
) H2 J( i5 H( z restore/ R6 \0 [- ^- t. \
}3 R: e" I/ |4 } J, f' z/ P1 s
( e7 _# P# @5 q9 U2 E/ f) N
else {
+ r( B l# }& X6 l
0 O* `3 p1 d* J2 I4 }( O1 m di "cannot find pminplddy240"
/ u: o8 t( k) ?0 E" J2 ? restore7 `4 Z8 N! h. _& z7 q, V
" }; F( w( W' F ?/ m6 U sum dx240/ u% B! l% n- v+ o, @
local tempminplddy240=r(mean)" G, i: I: Y8 u6 a) i* h, Y1 E: b0 k, t
: _" c; p7 Q# G* M: t 2 T% A8 p2 ?1 J; C
}
' R9 n ~ ]0 M* L8 n% N - R9 d# B9 k" h" [. A/ ~
/ N! p/ Q( P( F$ R }
+ k8 K8 p" v8 J- Q$ Y8 j
+ X/ y8 R: F& _1 {: Y
3 c) f3 ?. x' x/ p6 ?7 p gen pminplddy240=`tempminplddy240' in 1
4 ?2 B0 B' {9 H N
" F8 }+ z: H$ h *-------------ddy240pmaxp左侧高峰值 -------------------5 e5 B. n7 d3 P: D, w$ x
1 C4 S: F* t+ A7 J
preserve
6 }; P5 w+ ~( M ' H# U/ P( S4 y3 l8 I
keep if dx240>`tempminp'3 ]0 O& D3 `8 \3 X- O9 R
o& e P" i2 k1 ?& E9 R. p" k
keep if dx240<`tempmaxp'0 _: z/ S4 i5 B: j5 U6 E
; @! i: l1 l9 O2 ~
keep if ddy240>0
0 E% n$ u. d4 C% ~+ m count+ K- {% V( G, {8 v h
- r! m% s7 p+ V
if r(N)>2 {3 u \7 q" a3 U4 |7 |3 r
; Q3 T7 m4 ]3 e: Q) L$ F
pkexamine dx240 ddy240
& x) P! x( W9 L# Q% \
. x- W/ Y6 X& x% ^9 c local tempmaxphddy240=r(tomc)
% }1 F( t5 l# T! a1 i" w j( B# g* {
( ]% F( G8 T* B0 B, ]! t restore9 W( ~6 C% V* I* q& f' R- p
}
1 ]; T7 t8 |- x2 {, t4 Q- k" j 2 A3 Z7 {' m# d( r' |- q' K/ S
else {
1 [6 W% B) m- [8 q) F" T ' l* C3 t+ p* y/ k! ~; H
di "cannot find pmaxphddy240"# Z: E7 U: Q# ~/ F
restore
1 x6 p* H7 R+ @% _* R3 J" \- r$ F
2 d2 d' B/ [ ~- o1 a p+ _# {1 p7 X sum dx240
9 f* E5 q! o2 E' } a local tempmaxphddy240=r(mean)
$ J, W$ A+ Y9 k) X0 A3 V& L
- [+ l2 W0 H. A) u 1 u2 M& K+ `; H0 N# g& u- B [
}
+ Q1 Z$ S/ O4 n ! A% f' V5 ?' X9 M
6 H+ Z7 p( Z: m- c, Q! G6 ]* |: i
$ w G) @* V6 n! W1 X
/ q, c; H$ F5 s B7 x; _
' R4 Z) w3 H9 G 1 [( H) y1 [9 H$ _+ Y) ^
gen pmaxphddy240=`tempmaxphddy240' in 1% D! U. I8 m" G
, z2 w5 Y) l0 x - \& j7 w! G' M9 Y4 ]' q" S
*-------------ddy240pmaxp右侧低峰值 -------------------5 ^) s- c$ }: y0 O8 i- e* l
) U6 f" l3 b9 H1 H0 R3 `: G; O# |
preserve ' W' y/ A1 a) Q. x0 s/ {
y8 V' C( L. F" F: K
keep if dx240>`tempmaxp'
" X9 ^2 P3 ?1 i& }
9 K7 G# W" T1 p4 G& C7 K5 @ gen temddy240=-ddy240
6 \. r3 ?/ ~& i7 U$ Q e4 V ! ]" H& {# h% F) o, E# I
keep if temddy240>0
/ E. Z2 h9 B( J1 S0 i" j6 G' I+ e
! z) E" D m) Q/ ~, f% `/ ]) @ count
. ?) u1 ?1 w" D" V g1 x1 M
4 ~6 w$ h& O7 S# O2 r) g: } if r(N)>2 {3 Z9 `$ L2 g! { F3 r) U, ~
$ E0 u, h9 T9 B( l7 m0 y
pkexamine dx240 temddy240
1 z0 w! |. b: _0 J' U" t
' M: `( B3 F. f" | local tempmaxplddy240=r(tomc) 7 @+ T* n& X& k! ]/ p
restore+ A. R$ m+ Y2 I/ ?. J) S
} X3 K8 a# {! K7 ~- u8 `% l( @
: O3 ~" Z7 _" l3 C: y" I: ^
else {) A1 [5 |# ^0 ^+ o0 w: h0 Q! b+ F7 V& a
restore
% ^8 O! `" {2 A$ t5 w; j di "cannot find pmaxlhddy240", s) S0 N' m6 r4 s, x. V3 `. S
. e( l+ P( C) X# X( E2 }; c/ V% ~% S 3 r3 M$ R0 t9 ]" H2 G! R+ {- `
sum dx240
3 M2 n& y% Q0 j! A; e# m local tempmaxplddy240=r(mean) in 1
* O- M- E0 d3 m" ~ # G2 \7 q$ @4 C+ D3 n
* e4 K b7 N+ @$ }* Q" M }2 J5 i2 P q+ Y( P
1 d0 y- _3 E9 P5 [
( y: X* p) p& N( e, {+ r
2 a8 {$ L$ F& X8 E * f5 _- ^5 D; `# @; f! M, a
' [" C! p/ _# n7 X4 ~4 S
3 d& C2 O; q) _/ C/ g$ c$ F0 c6 m gen pmaxplddy240=`tempmaxphddy240' in 1
! S) x0 x7 s) k' m! q1 U- `$ ~
4 {# I6 B' x5 F: R *-------------------------------------2 \" K% E2 G! r$ F6 g7 X' }% ~2 d
/ D/ D! K" A4 Z
gen price5d=v5 in 1/20
/ @0 u1 h1 ~; x( x4 L ; O' |3 U: _9 p+ {
gen price5yy=_n in 1/20
& H# X0 \0 `& D% ~, [8 a7 G 5 z$ D& c& [, _% Q. _; O* e( L+ P/ A
gen price5y=price5yy*(dy240max-dy240min)/207 O( V4 k! ~+ \3 p$ m0 J7 z" s- p
- a5 K' v7 w1 I1 R; N( E+ y
*price5y &price5d* p# Z5 S% q; w+ W. `' h/ ~+ A/ R7 {
) E" z# ]$ B# ?5 P
gen priceny=price5y in 1* p" H! b9 v @% G% @& k0 s
: G q T/ z# Z0 a8 _
gen pricen=v5 in 1
8 `) w u: {: T' C* b* @5 R% \9 F( S; g. N6 j- ?2 _
/ |. p e/ M o" ?5 W9 Z3 O *priceny &pricen( y# X% b [8 ]3 U) _* D- S J
2 w( V( @8 K' ~& a, b* R# r* z( x ) X% n3 i6 c2 q- \
*-------------------------graph------------------
9 r3 [6 K) a8 }- y7 u) X * {% \' y5 J2 }0 f" m3 G# j) D0 R# 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)1 I4 h r' d; D4 z! Z* ]
6 a$ x' o* `% C7 N* ---------可选项目----------------------2 t" p- {; d4 h5 o8 ?; P% F( n
*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean))7 U7 ~7 E T4 ?- ^1 j
}
B: e# s6 C4 v. K3 b) w& r; Oend5 N$ ^8 ]3 r* V* q4 |
|
|