|
|
maodeng 发表于 2013-1-28 13:13 % {( B5 S" C6 @7 v( S' ]
. hello 300236+ ]- ^# z4 O) J! O- W2 Z
statement out of context
8 h3 u5 J% r! H; tr(119);
+ Q1 G6 x0 m% v抱歉,最近太忙了
$ h3 @( ^ V3 t8 _6 y* l* B/ n% T h% ?% \! j
300236 我用下面的程序试过,没问题
2 v4 r7 a9 a! {/ E9 y5 ]% d! F
) e) _/ S9 D( {8 t& N2 \! w你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试7 ]- N4 ]3 U: k, d/ k
8 H- U( M2 f q( n
capture program drop hello! ?! ~' b; O& n' E
. z) F! X- q! Q; `) S
program hello8 X$ Q: j+ z# g
; G; S6 n1 n3 b9 l% L9 z
quietly {
4 k- q x; @9 Y' ]* G4 t, F2 R
4 Q/ W7 R2 p, r, P/ wclear
4 Z% U9 t/ i) W: a% O8 @1 m6 w$ a) O- H
cd D:\stock\test\source' ?& A7 S0 ] A- v9 }, ~$ [3 t: A
8 c9 z; f. E2 F0 }0 Z
insheet using `1'.txt
" Z% v: x7 ~- A% h) ~1 h- v8 g. X& @; X" D! |2 Z0 }
keep if v5>0; G4 m4 `7 ^* \
; E, P3 J" C: R* {+ \
gen vt=_n
4 ?' d0 ^7 Q( R p5 C3 z4 j , j" N$ d% @8 R- @/ V
tsset vt
% @& E( J8 r- J: W, e
$ `: A- X" V# ~: p. G5 ] gen zf=D1.v5
% E$ ?5 W9 o& d( V# C/ @2 M7 _% \+ `6 Y, J u1 u# F% q
gsort -v1
* ^9 N7 a: H: s( T+ h9 I% p0 F- P- P' s% z$ ]
gen avol=v7/v5! K7 j/ j6 q+ S# A7 x
- S K. N; z2 q" e( Z6 X0 \ keep if avol>0
( s" e+ Y) d ^2 J) B$ d2 A, [
3 \0 X% Y* O: y' M$ u# g drop vt
4 u+ x. b) a3 I. ?- C
4 O3 C/ [. R) `2 k6 q D gen vt=_n
* W# @" u6 O x, g3 M$ T' \/ A
. U# Y- O3 o5 r7 C, K7 U" {+ U tsset vt: b+ j. T; e# N6 r
; ?1 x6 `1 g$ H4 x: p0 w
sum v5 [aw =avol]
8 g2 o. W6 a# y. y9 L/ R' z& f5 Z/ }7 z! v, ^: V- a+ D# I
gen amean=r(mean) in 1) N* _ h$ X3 C, B+ u3 t% P
3 {$ ^2 c3 {* A5 p) w( c * 总加权平均值 amean
: X# Z2 K5 j$ U) T$ d/ Z - E# |# d6 O+ h2 t c
3 t+ N8 n0 |$ b' x, _, J- g2 t8 o keep in 1/240+ h- g& N1 g; ?! O' q% X0 j5 n
2 d$ Y: ?0 G+ S, x sum v5 [aw =avol]" r u" p# |3 g$ M8 Y
4 T& ?7 L7 ~! `: E gen mean240=r(mean) in 1
) F8 A) j1 e' a+ } r! z4 {" K
4 u" V" w% y- |1 h% c M& x *240加权平均值 mean240! p; {( N5 O3 o; l. C
0 @1 y% ]1 f2 X8 j: x& r
set obs 500 ; u) G- V3 C6 ?0 _ @
- M% z# H4 |5 j: E: z2 Z kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
' [9 m R s* f
4 m: _( k) U/ L: T: ^" n) z *240 kdensity(dx240 dy240)
! t7 Z" ~* ~7 m/ y' P
/ J; q! {% m% h9 Z3 U sum dy240
3 s. z, p0 T0 }) k9 R1 ]
8 R" p6 ], O8 a3 Q, Z. C gen yxis=r(max) in 1
. a E: c/ P! f6 [0 A & n1 H9 `3 u+ ?0 n/ W1 ?
gen yxis2=yxis/23 z* U* }: x+ V& y; z2 g
0 ~% ^3 ?: ^0 {% a *yxis3 [; |7 t4 ^( N" U8 o T6 @$ o
! c- t. p& ?4 s; ]2 ~' {! {/ ^$ p gen dy240max=r(max)( F6 t( K5 V9 q: i5 E5 O
) C- [) z# G6 m
gen dy240minp=r(min); H9 P9 |9 o6 [
* c7 U. E% O) V! f gen vtt=_n
1 E/ Y2 ^8 R9 T# [6 @' @
. f* W1 O! Y: N2 p' @! y tsset vtt
2 v9 D' ?# f2 z5 p" b; e) ]: F" v2 V8 R) U/ q2 @8 _5 G6 a h t
gen ddy240=D1.dy240/D1.dx240
& L) r2 I: W# {7 q3 L 9 d0 H/ q- G0 i- }7 s$ ]
sum ddy2403 W, L1 c; d& Z% `: C% q3 R
; ^, ?8 S1 t3 v) w8 |+ { gen ddy240max=r(max)- L! C. |6 H$ ? ]6 t% L. q
- K6 ~; X5 }- b3 ^9 p
gen ddy240min=r(min)
, ^2 `7 e) t) b, o0 L* q* t; K * h6 P% d" I! a7 f( C5 e
gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)( e: d1 J0 O+ U4 E- N( m
$ g, K1 W: e: w2 J1 S$ C
sum ddy240g3 ~! }7 c+ O% H/ T0 ?2 V; N7 @
. W9 v5 j6 T. Y: C2 L gen yxis3=r(min) in 1, O% n- s* g9 \& X( {& K8 ` k, D
' H) }9 j0 t/ B( `; t
gen yxis4=0 in 1
- w9 P; h$ [" `0 c* x : r: ^9 j% g6 b
*ddy240g 6 B2 S; x r- P. B0 Q1 m6 e" A
! \, R, o. L, ~) }$ b9 F. |5 p' a
8 V* w$ x8 K, [/ G! u7 D; i- n6 c7 g preserve
/ p, b, R0 R8 s! b- D E 0 T' w( c2 P/ C0 U# h# @& I
sum v5 [aw =avol]* y9 T( i8 Z/ W( h0 e, W* M
+ ?/ c1 j9 Q$ ]* S; ^ keep if dx240<r(mean)
e8 Y/ p0 U$ l7 d' ] 1 X1 O: F" Y3 B, Z, n
sum ddy240* F4 {4 y( [$ b( d( K2 D; B
7 z& r% }9 j" A$ {( Y
if r(min)<0 {# _) b" i' y& s/ L3 G W
/ @- P9 z2 [9 Q; }9 [+ d7 Q8 ]4 y" U keep if ddy240<=0
- J+ S6 O! V( r
( J& ]+ H; Q& g0 Y+ Q count& S! l5 ]6 J H1 D
% p* F+ p* R& G+ j' r L5 [5 @; Q
if r(N)>2 {
, F( D; \) a2 v7 E, k
2 F) w. \$ A3 J4 ^ pkexamine dx240 dy240
% n, Q6 K. R: S
2 X8 A4 z* t9 a& | local tempminp=r(tomc)
; n( U9 K) | Z1 [" s9 B" a. b restore
# o( l7 P/ Y* b% B5 P }% I6 r& l+ Q$ ?! S
( k& }; T2 I$ D& M9 M5 N
else {
6 z: f! a( l1 e6 C. { r/ S! z' j 9 F5 D" n3 j, E7 B
di "cannot find minp"' e/ J9 e2 R. I& b4 t1 b
. ^, a: h. I5 ~0 \7 D% t6 L restore
5 q: B% I! Y& r2 d: G sum dx240
$ ?" M6 m5 K+ j* @" L* F# F8 | local tempminp=r(mean)
# K! Q' b* P% f, r' Z
# Z$ w0 h0 u7 t; h: ^* \4 @0 G }
1 a2 h) r! y6 W }- I5 {+ C0 B8 x3 m7 c0 D
else {
7 r' f3 q$ V- A: q. E
1 k8 W% }3 W8 v! O0 G7 ?. {& _7 e keep if ddy240<=r(min)9 n& P1 A$ U! C [) ?8 g" x) h
& M+ A x( }. A" f. \' C2 i. A sum dx240) ?" R) J- R8 k$ L v. D% f+ Q
( K# W2 C& t2 r/ V# @& d local tempminp=r(min)/ Q8 D! C- d: ~1 R) c9 n5 F
restore
. F; W( r s% g8 f }. `! C- z& M' L9 X; b6 }
& o0 v" n# {( @- y g( E
1 b! J, C) m* K& i3 R- d3 B2 M7 w0 P, H
gen minp=`tempminp' in 1
( P D9 R+ L1 ]& `, w$ U *240 minp
" _% ^4 u+ Z. H4 _" m) Z' `8 O V, v" B' L; _9 e# W
( @# Y4 E% J9 r2 z5 I& y* K
( @, w: X3 [% P' P& O preserve , g1 M7 C: n Y1 c, _9 Y
, F2 p5 F/ }5 J& y* N+ M3 N( j
sum v5 [aw =avol]
; a& A$ E' o- G+ Y1 u, o
% b2 r, o; |6 V1 i7 i keep if dx240>r(mean)
5 E# S+ y7 p6 ]1 ^1 w; k ( h8 C8 a' \8 R/ G4 C
sum ddy240/ C; i- B. P$ G I3 l! }0 t$ H
. Y: b2 }0 S1 f6 J- O
if r(max)>0 {1 w! [- z* f/ ?4 b# \9 C, p1 t
" N" H* t; z3 P2 O
keep if ddy240>=0
1 I' c* m+ |- g1 `* w7 Y. S 0 ^& c `, \! W) k( S1 x
count
, S2 M$ c+ z0 a/ [2 m5 x% D
0 a' C; r0 D/ Y' p# W if r(N)>2 {
0 Z, Z- }5 ~ [! V( G % a+ W- O& U4 c/ Z$ |! [
pkexamine dx240 dy2407 J4 b9 f }0 L5 ^/ J
9 A; T5 W% n$ T8 z
local tempmaxp=r(tomc)
/ c# P' t& z4 E R4 d+ B restore . J: e; p7 y5 U s/ j
}
( V9 Q# v ~7 x9 J% I k3 }. \6 X 1 m, F0 f) G" e. I; a! i
5 u; Y2 h. {$ Z4 D else {, g/ b: W# _* C" N6 O
restore # R6 k% L' U9 k! Q; v/ t
di "cannot find maxp"* b4 y. u( ]: T1 Y" N3 w
6 n s; n! m2 h* [- d" D& @6 q
: ~$ Q, j7 K( \( W. l z, M
sum dx240
& g/ N# j- m- O; k D0 D local tempmaxp=r(mean)
" |8 L" e) k, E8 z
; G. x& R) S# m2 { }
1 X0 ?& U& {& [. F. \6 K+ t
' E& i7 O+ `+ x5 i" H7 D" A }& v/ h' k. G$ m) V7 [6 m
" @" N* v0 v4 b, {
else {& t2 i, Y D/ m7 Q' E
4 y. I7 l6 }, Q( `$ ]# ]
keep if ddy240>=r(max)0 F! r% |& v5 b6 D& s* h" I
! a- R {7 s( T" s) A: d# I
sum dx240" R) c v7 E3 L X
( x9 q' Y x8 ? local tempmaxp=r(max) 5 Y2 f8 N* f8 Q4 |6 T9 r
restore
" g/ o: q+ [7 [- \9 \& R }
5 N7 @# K% j) g+ W9 x. p
! B* ?( |; P8 H8 c8 j# Q7 J7 X; a- M# J; y- c9 u+ g
- {1 g. q6 f; @( X- @: p* Z9 \) `% e h4 E* {0 J5 Y
gen maxp=`tempmaxp' in 1& V; u! x( e, S! e5 k$ Y, ]2 Z7 b
% Y- ?% ^9 L3 ^' I _' S. N *240maxp
6 T: [& o1 w2 g) z5 e
7 d7 j8 d: r, k7 B4 f3 Y2 [5 z/ b . e, |1 D6 W! F e! c) o5 U3 w! U
*-------------ddy240pminp左侧高峰值-----0 ~2 [. Q0 z4 X& z' M5 h0 Y
7 E5 O3 B: K1 l7 F
preserve
2 l. L+ K2 P6 L; ^/ g- ~
% L3 P8 e4 ^" R% |: B8 e# e keep if dx240<`tempminp'( [( R2 v" a% j
1 Y" E# L# V" c9 g6 ?8 d
keep if ddy240>07 K6 H; z7 e$ A: c! {
9 ~& t; \ r! O4 x. V. { count9 ~: {2 c# X+ _) J" d! Y2 H
: ~0 ~6 k3 X3 A# m if r(N)>2 {
$ ^3 o+ [3 j( b1 l: A' U ' H+ g0 d$ _# a, e7 K5 V
pkexamine dx240 ddy240
. i l/ x( f9 s2 v" T* G . L3 f1 {- n0 |
local tempminphddy240=r(tomc)
: G# O7 h9 B9 w, O& B5 H5 \. `* |: _ restore
# ^0 o7 W& u6 k, }: T# F# h- p }
! F7 X3 U- O N2 L. ^6 ? * J. l0 G3 Z# s3 y9 F+ D
else {
- \" @, K& Q4 F- {: B% K restore
$ K6 P- s! @2 u di "cannot find pminphddy240") @1 |2 w- c W" {" y( D: H
( F; `! b- F% d* V7 ] - V- S F5 P! e) x! b2 Z9 q% M9 \
sum dx240& I2 y; M+ ? J! O# l( o0 c
local tempminphddy240=r(mean) 3 @) N' z' b9 g2 X
+ E% `: I! U6 \: p+ i# Y0 v
# P. ]* f; u6 R0 ?: C. F7 ~ }
! y0 l! I9 }. S
( L7 a- X. S" x* x( J) a * [- M. E/ g# V+ d: J- L/ [
. T4 ^" P+ M; [- E6 j
1 E# F7 e; M( ` r- D3 ] ( R, [3 _ P: d* J
/ J# O* h/ d/ v
gen pminphddy240=`tempminphddy240' in 13 y6 }: u" y; a3 L. D9 v) ?$ J
1 {7 }4 W8 m8 l- e9 [8 w8 q7 q# `
- v, u1 l3 ^+ Z4 v* U0 @ *-------------ddy240pminp右侧低峰值 -----------------7 L' ?; F$ t& x1 K5 s
preserve + K' y. d) C7 t1 F) k/ }( [
5 [3 Z6 J6 R9 D. u0 V
keep if dx240>`tempminp'
- R- G7 } q# e1 _
! [' E! Y. S: M/ E9 B" k6 f keep if dx240<`tempmaxp'! j2 U" Z, O% r- m, l
! P& L1 p. j, i% z+ T, b
keep if ddy240<0* J4 p- o1 ^( l, Z3 v
& l* F/ g V5 H
gen temddy240=-ddy240
3 ~6 S7 i' H1 z. u j2 g/ N- W" d" A
count3 z0 s" u% }( r5 ?, D* j% G! R+ v( z$ O/ J
0 U- Y5 V9 n. X
if r(N)>2 {( T& |$ Y* Y( b! o9 m) W6 u: a
2 W/ z3 G3 T4 N1 t pkexamine dx240 temddy240
! a, |( k6 Y% S' C2 h: U6 o, Q
: g, y( T+ \+ y% s! u+ a local tempminplddy240=r(tomc); G9 ]" y4 n p
restore
6 {! C: q" D7 Y) s/ t& j7 g. D }4 d! ?, C" D) v8 Y. e0 B; a7 L8 n
$ P @5 M# | s# C! v1 L# h else {
( N$ S1 }8 y( F: K5 @1 z % U- ^. f! J# r: U9 w
di "cannot find pminplddy240"- W7 _* l# v8 \" @8 M7 o
restore' n5 `6 ^- U% E Z% D6 [" J
@6 V# K2 X; J, i& r: G" h
sum dx240) t9 I i4 v' w1 D g* K
local tempminplddy240=r(mean)2 V% I6 T- }7 i6 E, ]
" p4 ?4 q3 A. E/ q a ! V# _ Q: O5 P1 f1 `
}, L2 L+ M) r+ v
4 k6 a8 Q- x: O) e
' G, h0 z) @+ d5 o% X7 G
; r4 v4 T& _: E4 m$ s" ^
% M$ U3 a7 C" J7 s+ m' v: e$ j
. S& P$ [: }; U9 F( y" O( i" ]: e gen pminplddy240=`tempminplddy240' in 1
2 J, k0 j ]. w. o1 C# B* G6 ~ 0 U) v8 p3 K/ `' y6 Y/ j8 M2 s6 y
*-------------ddy240pmaxp左侧高峰值 -------------------
% q$ h! K* @1 W 0 _8 u) G# e# a/ L
preserve $ D% K( Q6 |9 Z/ m; M
6 F" v8 X. L) g& C& a: {
keep if dx240>`tempminp'6 y2 Z/ y9 A: t5 ], w& P
! W# I6 I% h# E( \% R3 ] keep if dx240<`tempmaxp'
8 e( `( j8 K+ D4 a" ] 4 h% O2 D( N! h; c+ P* Q' g
keep if ddy240>0 [. L+ j; M: q! v+ T; s
count
# B$ P. K/ ~1 F
' D) T2 z! c1 _+ [2 A- A; G if r(N)>2 {
+ K* G1 y! v5 \4 K/ Q
8 R* t- k7 @% O9 i pkexamine dx240 ddy240
$ F1 p( Z& n6 D
2 l; ^6 q( m5 k2 N0 s4 u6 z local tempmaxphddy240=r(tomc) S( R# ]9 M8 D& a$ V' n @8 _
! ^- m/ W) Q3 C4 E& \% r1 {
restore; u, k/ H! c/ F" ?% d, i& F8 X
}
4 {2 P' l5 c% [" _. J0 V
/ U8 C8 d, Z: Z7 ^4 g else {- }! Q* @( n* O% E
, b4 K9 A2 t3 K: c3 Y
di "cannot find pmaxphddy240"
4 b& r5 l; _/ |: z, @1 F6 I1 o3 t restore5 [2 Y. l+ I6 _" z W! n
5 i% W" M4 u$ a6 |- O0 _: o8 q8 P
sum dx240
) b! K( w5 e; b9 C$ P local tempmaxphddy240=r(mean)
3 g( r) I. y* q' D- k7 E # h# m6 J! \ M+ y0 r% B
2 o: q3 a6 |" y$ x/ K4 e& c( m8 y }
9 \! O. d+ j6 S* X- Z * P [2 s$ X% b: W! Z! Z3 G
/ Y+ }; O3 X7 S) a. m' L & t- k6 V0 J4 M% R% `
. S8 f- o( G& N2 x
0 U( F' d' `8 N4 m! L5 U, h" \ : [$ M9 R- R6 ~! C
gen pmaxphddy240=`tempmaxphddy240' in 1
; ^( k: a- e! A I7 d 5 }& g J' t7 |- b8 [, I: u. r
0 ]# U2 g9 |. T# F *-------------ddy240pmaxp右侧低峰值 -------------------
6 z4 x: S6 w7 B
# }1 s9 U. }' j preserve % v) _5 c3 L2 F8 ^
0 B- Y0 t8 {: x2 r5 ~: b
keep if dx240>`tempmaxp'
+ E' b, G, M# |+ c+ A 1 ]5 K# k7 s; m8 S) L3 X: L' E1 C
gen temddy240=-ddy240$ o! S3 e, Q& v5 y6 |
( }* y4 k: X+ t+ d7 ?) ] keep if temddy240>0& R) D5 V- p) E7 u# g8 l' w* W
& L" o3 u: I* b- w3 E9 l' `9 t
count
( O4 A$ R7 o- A1 b- N
3 |+ \1 z# G: S7 W! A- Z if r(N)>2 {
& [$ A. P+ w, r' z! t3 Z 4 Q% e& z3 S( B) G* u8 ~& F
pkexamine dx240 temddy240
6 b3 a1 p ^! v0 i6 B. I# i# s
/ b$ B/ P, ?/ G: s% }1 k1 q* Q local tempmaxplddy240=r(tomc)
/ v; k3 M: w" {2 y: m, V% \ restore
* h7 B7 I0 i9 s! \& @ }
4 @3 G. s% h' W% ]. [
- g$ T V3 P. w. x6 G else {
+ o2 e/ e- @3 v restore
4 K# F9 `$ j( d7 V X9 @4 m di "cannot find pmaxlhddy240"* U4 M7 a% ?- N1 k. i2 k1 E
+ F& b' \! a5 T) k7 c; k2 d
/ i' Q8 M) Q) u3 s sum dx240( }4 F2 Z5 N* a' o- B3 L
local tempmaxplddy240=r(mean) in 1
2 n: ~8 @: a% U! U/ G
, G6 H& z8 f/ J8 n8 }& \
) L! H* }. y& A ]$ h5 C2 ?7 h: \. N- V }
- T! E3 J+ N4 ]5 T1 k" b
% j) ?' {7 ~2 T& X# N. l! f* P H $ g" D+ O2 m& w* a) v" Z
( l2 S' X! o& d * n6 V: [6 I. n
. ~7 A( e# b0 ~" ~! ~; U. V/ y) o , O+ ?8 M) a/ b5 f
gen pmaxplddy240=`tempmaxphddy240' in 1
1 ~9 p) _' I' f" ~
" y3 T& M P C" [3 D& G *-------------------------------------2 c) }$ y0 u- I1 W5 |& k
* m4 X9 _( C7 x- H9 n7 C9 W7 [* L gen price5d=v5 in 1/20
( p$ w6 |/ y Y4 i+ |' j! v ! T' E, l: F1 N# a
gen price5yy=_n in 1/20- v- ]) o! r K
9 H, @3 ]- P4 a' N/ g1 G
gen price5y=price5yy*(dy240max-dy240min)/20
; W# V- @0 {& R: x+ \% z
. C* a) j- Z6 V; p7 H2 k8 o *price5y &price5d. c Z, s) O% b6 ~$ [
+ e) ^% O9 G6 j; ^; {9 y gen priceny=price5y in 1, y; k, x3 \% j! Z, a
$ I& z0 b7 v. Z
gen pricen=v5 in 1
% K8 X" V# \" U6 W7 O5 N/ P7 ^6 @7 r5 U( \' x, H6 i3 E
G8 C7 \3 G% s2 c7 g6 v5 q }" S *priceny &pricen( ]: b' s( f: [% Z2 r1 U8 ]
, h, |0 a( A. B: m+ ^3 }2 L* Z 2 _4 I7 g% i! t) W/ n H
*-------------------------graph------------------
, _, \6 l0 t T1 k: X1 w/ v& ?( @
7 T- c+ o. z: M/ a8 U: g: y* T8 t 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)# L0 e5 b* m/ |# w6 t% L& d; \8 _4 t
, s$ k7 M. x, I2 }
* ---------可选项目----------------------
# b' T/ N6 y, G( N( k*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean))
. s6 h% o" W% Q# P) n}
0 |2 g6 n# |% L' K: d; \; H6 Qend# J- E, ~% m% ~/ w( @; n. `
|
|