|
maodeng 发表于 2013-1-28 13:13 s! d* K$ Y9 [- h% g; f
. hello 300236/ N3 ~, G7 n7 f: P, j8 s% d7 I6 O( C @
statement out of context8 W! ?. S7 }. u3 F/ z. e
r(119);
8 a: i( B) R& F, Y* U5 p+ B. O抱歉,最近太忙了1 u+ _* k4 \9 U2 N
" E4 _% ~% J( ? H4 ]
300236 我用下面的程序试过,没问题
$ F+ f/ Y/ ^# @/ X% L5 F
3 m+ p, y6 `% S3 u6 d你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试
" x0 i& D5 d+ ^/ Q- j h, B5 a) I8 G
capture program drop hello. j% H+ G+ Q$ h
7 _" F6 _3 q" G }* e) d* }
program hello
7 G8 f" O6 \; h( d2 Z: w; B& U9 C" m% Q6 l+ O
quietly {
" r. p6 r9 X- n/ w+ t
3 ?! W/ d4 g: h0 X; |; D: m# Yclear& r& i4 N$ M% ~% D
0 a4 a# f2 W- @* L" o
cd D:\stock\test\source
9 y0 P( w; t" h( \( D/ v% S, f2 T! m& R
insheet using `1'.txt; S; J [' n2 P1 J5 x
) N1 }1 z: F" ^1 p% c
keep if v5>0
: D8 H: d# C2 p
$ N, o8 R! n$ f! `" }3 D. B gen vt=_n/ J9 g6 j3 K8 U* `- l- ?" Z: R
- V% p2 T, n }. u, F( D% S4 j B# ^1 e
tsset vt. N4 C! h2 |) x4 t+ h9 @
2 T" W2 L+ B+ G9 Y0 } gen zf=D1.v5
+ U3 R7 {- X: V+ Z( L+ D3 J2 Z+ t; @/ a8 T0 _
gsort -v1- e7 y. ~: ^* s _, K8 B
; k' V, U# [5 D gen avol=v7/v5$ H% I. q! F2 _& X
. K% o9 t: h- @# t keep if avol>0
- Q7 ~9 n7 T( i* X* P ! @) o V! ~ v) q' p; q! v
drop vt
: y! K: X/ f5 W* R5 M; w' D" I ) E( C' W }0 A
gen vt=_n
' ~$ A9 X" @. ?3 b2 D- { 9 M- H7 ?' s# X1 j. v3 B% M* Y6 B2 N
tsset vt5 t- j u9 j' n( T5 n( m
% L) m6 v' r/ n3 X" |4 r
sum v5 [aw =avol]
V+ x5 D$ O8 A+ r& T8 j$ K5 H6 m! M6 ^) \8 _+ P( R
gen amean=r(mean) in 1' L. Z. p6 j7 ?
! q: d4 M' [4 O" i! B! _( I5 i
* 总加权平均值 amean6 M% V+ ~" t3 u- \' h; e
7 F- n1 U3 o4 h& M, v 7 f: ~ N; H6 E/ l5 G9 v6 x
keep in 1/240
- i M; E' { G K# `: _. x! a
* m1 T/ T1 p1 W. S0 M: U sum v5 [aw =avol]2 ^' Y0 {3 ~/ y8 ^8 o; ?
; a( G# v$ ]: E" F! j; ? gen mean240=r(mean) in 14 g7 ]' i% j! S0 B* o
4 j* L7 f5 b+ T; I$ O: ~ *240加权平均值 mean240
# s6 O0 J5 d t2 N
6 [/ Y8 l6 E' v) Q! n: [% Z: | set obs 500
; k8 e+ k+ r! i7 T. P
6 |: _! H2 x. P, x6 e kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph) Q; |: x6 k' W% I& Z p: G' b
/ u% y+ g4 A' A- v, a *240 kdensity(dx240 dy240)
, b0 E) S: U# D8 R# O$ ] & F3 X% ~2 L5 p
sum dy240- r* X. Q! i2 J K' d H
# q7 W5 ~9 `- g9 e N# v# m3 L
gen yxis=r(max) in 1: a0 n, e" C; p- ` ^% c
: R7 n C1 X+ u: s( W0 t. l gen yxis2=yxis/2
3 l$ T) M! X' Z( [ Q" T9 H
+ r w% Q( a- v- z/ u9 }2 o *yxis3 P9 i' f1 V; f6 _8 ^" N& D
! |4 u0 n5 `9 \7 N: X0 k
gen dy240max=r(max)
7 L' L9 T- z# i. I- B
' m8 }, K" O4 P# T gen dy240minp=r(min) _+ d; ]! T5 U
( E. w, F( R3 B' v: Y gen vtt=_n4 Z/ a9 Q2 H2 W. D% ?7 ^
* `4 \- Q- k0 T& A
tsset vtt9 k: ?% j9 s p. h2 H( I
2 |) d" b( m5 x4 T/ E t
gen ddy240=D1.dy240/D1.dx240: e9 }$ T; N3 a
# D9 h7 ^/ @/ H sum ddy240
7 | e3 u9 B7 B! C 1 ^" }1 o, e/ Y
gen ddy240max=r(max)
# L! t9 H. h2 ^. X # t: B1 G( R* F+ {
gen ddy240min=r(min)! O& u: ^! h2 g; H0 D, o/ N8 f
, g+ `0 ^. _8 Y0 X( O/ K
gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)2 ^+ V6 F5 P5 V
; S1 a9 Y' m+ q0 _3 [ sum ddy240g1 E8 x- W: [+ M( F5 O
, v' `- p5 i* ~ ?+ b gen yxis3=r(min) in 1
6 z9 \0 [1 p; o% I2 ] ; Z' g% d/ Z5 E. A0 L9 K
gen yxis4=0 in 17 Z1 W! \/ |) w9 u6 B9 t u# m. T
+ W( K( z* _* r *ddy240g
/ X4 [% A# d7 o2 I) O 7 f" r- h7 O0 J @
. r* @5 ^, H, T; i% r# ]7 p5 J preserve D! ~6 \( i# P# P2 }$ O( H( o9 k. s
( i# U( ~. V# L4 ~9 ], V; `
sum v5 [aw =avol]
" t- U! F) a, p
# c4 U7 y# l) {( h/ @% s keep if dx240<r(mean)3 j. A. c& h: ^. f9 l5 O7 @. `
* x, F S' z. ]9 `! x+ b sum ddy240
! x; i3 g8 @0 P( p/ S4 q( ` 9 P* z' I' |) |2 ~
if r(min)<0 {( K, a- O' I" w9 g; n0 ^
3 Z' Y9 {# r: B5 C
keep if ddy240<=0
W$ d& p5 B) ]2 L % ~: M) g7 R0 o0 O- i" m
count8 N# t0 t" G$ B
6 b7 Z/ d: s2 w if r(N)>2 {' Z9 r; @9 ^7 S, z8 s6 _2 V$ ~
3 w7 N0 p8 ~* z" n4 [% A pkexamine dx240 dy240& m0 y% ^) l9 x
6 ^' y0 z/ T1 g6 Z3 d5 l
local tempminp=r(tomc)
# L% a- h4 N6 W% X3 G Y' k' \ restore
* Z, E: z2 p: @9 \ }
6 p2 ~2 d) I6 K. b9 H 0 s, Z% C, B# J9 c
else {* \. r3 z+ J# o0 l: M0 k/ r9 i
9 }# A" m* S. C, s$ J7 [ di "cannot find minp" r9 v# T# r3 c
/ N0 y/ l( k% L- ^3 v% e) `
restore
) ~- ~+ L, R6 S6 K, {8 T sum dx240* r5 g+ R' |# Y8 ^, J4 ?
local tempminp=r(mean)
8 C9 ^0 L# s# Z& G+ X5 t
% S% [( B) O" A1 ^ }
o- h" e8 J M- o/ i o. i4 q }
+ I0 v" Y6 i0 K! Q% B2 N/ S else {
, s0 \: j! _/ z1 ]* j0 N1 i* e
9 Z' v: q8 Q: n P6 A+ H( f keep if ddy240<=r(min)
9 j7 I/ z! q4 h& F! _+ r
* j+ H% _8 w( o' c+ \ sum dx240
7 u* D' I3 P" x3 r: r- l/ Q
7 D% _' p8 `& I! D& {1 ? local tempminp=r(min)
: |9 P8 x. W7 U/ l% y/ K- |( | restore
7 N. ^3 A. y+ `: p/ a/ B- G }
$ H0 \4 r' {: r, }
) \' }) T0 }# ?8 ~) ~3 t/ T! d7 `7 F$ s3 ^0 w* S
: ]3 Z! S& r: r$ I" c `. l, T! Z gen minp=`tempminp' in 1- ?, U+ i$ D T1 G) \2 x; q2 Y
*240 minp
; ]* z2 U: r9 w j) q9 w V
# i- q) W, R1 `1 e
1 `: d% U- W; X ' Y9 _- Z7 S: i7 M7 N' p4 Y) r5 [
preserve 9 o7 m }$ A1 m& G7 b! v9 e/ x. c
( q& v- s0 o# S, ^, I( ~
sum v5 [aw =avol]( x, g# w0 a7 I9 L* B2 }
" F3 d3 | J, o; _1 M
keep if dx240>r(mean)
7 d) N) ?4 ~! [7 W
7 A6 E) d4 O9 @0 |" b' O5 O; d sum ddy240
9 q8 A0 H5 F5 P( N& {
; m# E' t& v6 w7 n3 {# o6 w if r(max)>0 {4 |) H+ G. N$ v8 J; ]* Z
& u7 [4 r; L/ H3 O8 Z
keep if ddy240>=0
3 z1 [% v6 o1 W/ Y* q5 R0 o; h, W4 Z
7 O1 A- B, N4 B4 A- x7 f1 m# d- ^4 P count5 d5 S1 z; d* p1 k0 F! |
* p9 u; }0 F! r: u
if r(N)>2 {# q5 ]3 [0 l( i+ l" S& d6 u! E
+ n" O3 Z& V0 ]% [+ H# ]
pkexamine dx240 dy240
- ]& q) P: P. u& Y# G/ ]7 a: Z
) E5 z, b# B/ B5 m. D+ C local tempmaxp=r(tomc) / H, X4 k' S& T# Q
restore
! g6 q* _8 ~7 [ }
# W2 J# [0 a6 X. X! C1 v 2 p9 Z* _9 Y; z5 q
6 {2 N: i+ a; c- S N4 P( F else {
/ o5 j( L a O restore
3 O: t8 m+ G' ~/ ?7 M di "cannot find maxp". g6 e: ~, J' S5 R/ k
. M) u: V% {7 k- p1 Q Y9 O
6 Z' f8 |/ w a/ u sum dx240
+ u5 O6 L6 E3 ?2 m6 z2 a( e Y/ [ local tempmaxp=r(mean); c& Y$ B7 S0 z
, D& X. s2 J: x& g }
4 @! N9 F# d& ?: u/ n9 ~ " D7 ]7 g0 j. y, A ?8 _' `
}
2 u3 W# j2 z4 O2 q , J1 m: }/ e, L; Q0 S0 n: M0 K
else {0 _ O: L! c8 Z
3 T$ l! U$ o1 l# Q( {6 Q d! X
keep if ddy240>=r(max)' u5 [* M+ c' i" ^9 I3 ]0 y
* H# g S0 f5 Q! @+ s1 D
sum dx240
6 ?: r: m' |- s + F$ b. A# X! _& S: M9 x: s
local tempmaxp=r(max) 9 l1 c& {: r' a
restore 5 A4 K6 b6 }, y z& c2 n3 f
}% S; X: Y/ ?) z
' i8 t+ v: U/ S ~! q0 L- o
/ z3 D( m: r) b0 U' Z' O4 |7 [/ I' [
# R6 p- x9 R: Z2 s2 p
" s1 G' P4 B5 ?$ G: e d+ A1 [ S gen maxp=`tempmaxp' in 1
4 o8 [% K0 p2 i. ?5 d: v
6 K$ u% J2 P- e9 N *240maxp
' s& A& `$ H7 ? ` " f5 I4 V5 Y5 w. H4 u
( D) T9 B, F8 C/ F) d4 I9 A *-------------ddy240pminp左侧高峰值-----( y. c0 N9 ~0 a1 V
: G; s7 K2 p1 ?3 g
preserve
s# w7 C+ K* K) P |9 L0 F) e
& {% k3 _3 J5 l5 V keep if dx240<`tempminp'
/ }8 V4 H4 U4 T, q! K B* u + h) y3 H3 u2 {, t4 d
keep if ddy240>0- i. m+ ?; B6 q! G0 r2 Z" |7 v, Q
, }: l6 f2 }* @; X1 p) j1 S" j count, j% [! p1 }5 J. Y5 Q; R$ y
* g' @2 H6 T0 N/ [5 f& M$ F5 x D
if r(N)>2 {
$ h8 ~, ~% L8 f6 C
6 [" k" y* F1 [% ]6 S& C; {" g pkexamine dx240 ddy240
2 S' ], [% ^& s; x 2 V1 t9 e M9 F$ j' X8 V
local tempminphddy240=r(tomc)
# J9 A/ `+ F- L restore
6 L& S- N8 j% h3 L }1 ?. L& W7 t) w3 Q# O
8 _! D5 S* m& T/ W& V( w else {. T6 h; `7 d* d! ]* N2 L) [
restore
7 w0 ~ N: j$ j3 ^- {, I+ H di "cannot find pminphddy240"- T0 k. B9 e( R) {9 a& V' i- t
% `4 o2 h0 P6 l6 z; X ' K& o j2 t4 `# G) e
sum dx240
5 r) [5 }6 z2 P. t9 i1 K local tempminphddy240=r(mean) . z4 ]6 M0 ?- Z" U
% t5 n7 G3 X6 |7 I7 L# W+ y
7 p7 P) T4 q" e* _0 ^( J, X5 ]3 E+ v }- Q8 G& ]' c* `% ?
1 Z; v+ D. [& m5 U6 O/ q* X
+ e' n' S# I8 ^4 J , m. h3 T% C3 k" s5 Z
0 Q7 { y: l' R! P
" r# s+ ^) f4 W; {9 [1 b5 W9 l J ' n9 c+ N6 B* ]5 |
gen pminphddy240=`tempminphddy240' in 1( R, s+ U/ B$ |- ~! F8 a) o7 V
: G1 e, t4 L/ }9 c6 l
F y. D6 E2 r *-------------ddy240pminp右侧低峰值 -----------------
- R Z, F$ z3 q9 \, L& y preserve # v" q7 |+ @0 c U0 d- g+ K
: B, ~- R1 _3 r1 n- N5 M keep if dx240>`tempminp'8 I' s5 t- p% B
; n8 M' a/ S5 e/ } keep if dx240<`tempmaxp'
1 D: n8 N4 O+ z* m 7 r+ L2 ~1 _ k1 H5 b/ Z
keep if ddy240<0
" W. b6 ]* ?% O f4 x4 c% E 7 v! {8 A; n* ]9 O5 e! I
gen temddy240=-ddy240
" ^+ [# O4 r% e k3 R7 N# Z0 e, g
count! |0 B7 V% f; Z% T7 o: n
$ s" R) D: M/ z9 H/ ?" |, b7 I/ t* V
if r(N)>2 {
3 }4 p" J6 |/ f2 h2 N& S
# r) H+ E+ Z# K/ v! X1 H: m pkexamine dx240 temddy240) |5 ^; N; T6 B
, n5 q: N4 g! x% S7 J local tempminplddy240=r(tomc) v- @. h; _$ g$ V
restore
) K' @6 ~6 k) N5 {0 Q- c1 P! B }: b4 f& {& J3 M- g$ s
- k4 L, u5 E. Y Y v else {
- d0 B2 W. ]& h/ f
( p% E$ X* M! z( w di "cannot find pminplddy240"/ Y* g% l" Y4 T8 Z( Z# a K
restore! W# M( |6 H* s% B m* d3 V* G
! t! a4 X8 a! L' {3 Z; r sum dx240
8 {; Z1 C# s3 i& t local tempminplddy240=r(mean)
/ P8 P# b+ t: B% O2 q; \1 F& K
( z8 F$ k/ _; X( h2 b) Q. \
& t% s7 i" V( w- D }
4 s& L8 }2 Z: @# y6 G f# j j, {0 W. m' L2 Y3 q9 G
# v) k0 H6 Y8 G ( |+ q$ G* u( }
3 j5 j9 K6 o: N' D
9 L9 k% [+ _- w4 Q1 v2 R gen pminplddy240=`tempminplddy240' in 14 d' R. b* [' d$ J# c6 B0 [) v) a
3 G _: Q z f# ]: R; }
*-------------ddy240pmaxp左侧高峰值 -------------------
( Z( f( p" C$ c2 m9 l
/ S, s; E" o* Q% q* R! r9 }# S) Z preserve $ q: @' d' \$ [, d2 [: q% n
1 y4 F+ q# F4 e
keep if dx240>`tempminp'- a% i0 `( T$ ]) c
! ]/ b3 T" s: k7 N. k! E! W* n keep if dx240<`tempmaxp'# Y3 z; }9 O6 E' h
3 z; E( l* B# ?6 i# v9 J keep if ddy240>0' |) m, @* W* ]% S0 p
count5 N; W" _5 w& N3 B
# o- I, {7 f- y* b, ^& L- o if r(N)>2 {: E! `5 D& w' C7 `. l# O- V, Q
" Z/ o# }9 O; X6 R% R0 G pkexamine dx240 ddy240
, A8 h) O! e$ x1 n/ k6 p0 m
% |6 o: ^3 F5 |( \ local tempmaxphddy240=r(tomc)
7 O+ D# l9 H- i- A* \5 ~) O! U0 j% v
! i3 y* q; F7 U restore& G7 r" j7 t& e' x6 i9 k( C" x
}- ^8 ?5 i% d0 ~8 S( H# u
- v$ _0 E+ y z! i else {
' Z( B+ W5 L/ E A, D( p! c$ {7 P5 d$ Q
di "cannot find pmaxphddy240"4 v# F* s3 `6 f! c2 a/ L/ q# U
restore" g/ Z& u0 { p2 U' C3 V
: A7 E- b7 \1 _, ], C; @' W s sum dx2404 V O8 D# B8 g; \+ {* {" q
local tempmaxphddy240=r(mean)
% O- m2 E7 m6 m% t
) g5 o9 B9 N6 ~. V! k
: R3 c. m: T* t w( e7 [: X) l6 Z `( I }
. B a! m9 C+ P3 V6 V) T4 S 2 \% h7 I. H# e% F" N
* L; w% ? y) k9 u' I* E
7 I) i) p0 g; Y5 q0 _! t
# [ |/ z$ U. v" \ 8 x/ \: P) v& _3 S
$ _* J3 T, }* q gen pmaxphddy240=`tempmaxphddy240' in 15 ~* K& G- H( g) t, u. @0 k1 d
1 [: {! c' \4 A" s7 L/ ? {% B
5 ]) K) T8 ?" d; f" Q% ]: c0 Y# G
*-------------ddy240pmaxp右侧低峰值 -------------------
6 ]/ A4 E$ b/ K
$ Z, k$ Q V b5 t preserve 5 G/ g0 P4 w0 I2 C
- C+ N( }2 U0 H9 r( }( H keep if dx240>`tempmaxp'
7 q Z( K! F6 L
1 Q/ a8 f0 [. S3 G% v gen temddy240=-ddy240! p1 m/ N/ Q# w$ o2 e* B) L) c
+ r4 J m# V$ j C keep if temddy240>0& W+ U! n! F& W y. Z: |$ Q2 F
1 n' b( j2 b6 Y& h, B+ V0 J
count
) E( e8 w# L; t ( b0 W# t3 N/ J! }
if r(N)>2 {, u3 z- n) t$ b1 C: ?
6 l" N, B* x! Q0 F4 ]) ]6 V$ { pkexamine dx240 temddy2400 J- ~/ G8 a* S- w& z2 _7 ^, p1 L
; W* p: |$ l$ O1 C0 s/ d: _, }0 ^ local tempmaxplddy240=r(tomc)
' H8 O" ]# k4 Y2 f G# M restore
9 F) s2 E8 \& I, Q }* y8 C/ [: T( ^! s6 Q5 I* O" m
) }8 _$ I% w' p# w else {% J' [% b# T+ S+ _, Z
restore; |6 B4 ~6 S3 q- {& i
di "cannot find pmaxlhddy240"9 E9 f) ?# ~* C% G# `
1 X8 O( Y' M0 g8 q 5 z* \3 Q2 o8 r6 y9 W& C3 U+ K
sum dx240
M6 e0 f( d* S1 l8 s local tempmaxplddy240=r(mean) in 1
- W! W8 v, ]1 b8 l% D+ P ( ?/ V6 u" d1 F2 \9 B, F
3 c' X# g, j1 F% H' b# O }3 T% O9 r! z ~# S. q- m5 M/ a( Z, O
3 m b$ T7 y. J
* z$ }% m$ T5 |' U, P( z
$ L N( D. T v& a# H; z
' |+ T- ?2 | b% c9 }& J
, i- m( R" A1 V . F" S/ y9 W3 n9 J$ |
gen pmaxplddy240=`tempmaxphddy240' in 1
5 q1 o; N& m) L( z1 D- {
7 Y4 Z0 d4 ^% V/ T *-------------------------------------
9 @ [; ?6 d6 ]6 t2 T5 ~ 9 Z% _# l& T" B5 r3 V6 {" N
gen price5d=v5 in 1/20
: [% a3 C7 @* s ! e0 R6 a8 N& Y- E
gen price5yy=_n in 1/209 f1 i4 L) v2 P
3 `3 ]0 g; J# S3 D
gen price5y=price5yy*(dy240max-dy240min)/201 u4 Q9 p8 [# L/ \1 E
6 Z+ v: O7 h" q. G8 _
*price5y &price5d
- P9 o p) x/ |$ D/ t( F+ n/ r& j ' x: q6 W: F& j. e
gen priceny=price5y in 1" L l/ x$ j. x8 x
# @" i; F. N( l- V5 ~8 k3 e0 G
gen pricen=v5 in 1+ n6 ?* K! i) Y$ K
: V' U+ [/ A( s: w. J1 S ( F4 i* n! |2 a5 Y, O
*priceny &pricen
$ m/ h' I* x+ v % W& {4 {2 y: E: O
. B' w6 O, N3 Z3 j
*-------------------------graph------------------9 B& u; Y: Q/ b: Y
5 ?3 `& y% H% D4 R- _4 s
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)% J. R- D5 g+ Y& R9 D/ a
+ o7 V5 I3 }- V* Y
* ---------可选项目----------------------
; ~4 p1 b) I- s: O9 t4 J*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean))
8 N- B$ y, T! D2 T# S9 \}( t- [! k' R# t$ z' a) r
end' v. A8 k4 y/ }* f1 O1 `
|
|