|
maodeng 发表于 2013-1-28 13:13
6 @" F% I: m% n* @0 Y. hello 300236- [3 \. H( I( e" ]: \) u
statement out of context% }7 Z9 y: C8 c+ i6 ]# G( n- _
r(119); $ S, u; {0 `2 |5 g3 T: L5 I: ~
抱歉,最近太忙了7 K3 H3 a w* g" n* M
9 b9 Z1 `1 u1 p$ g' G) k
300236 我用下面的程序试过,没问题
# D, ]0 L n' B) Q+ @- d) y0 L# d1 h' e* y$ W G0 n7 L* M
你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试# X4 ^+ W% P/ T0 t+ o
- q) \7 h1 M ^, B
capture program drop hello
2 Z; s5 N5 h: X, ?+ y! Z1 t& }3 ^% H3 o# Q& _
program hello v* T+ ]- T1 K. |
4 H+ x( |! K9 ^: p' x quietly {6 f3 J1 x9 J+ g% q0 c; c; s
. U$ a% W& J! bclear0 ]( ]2 y9 o8 i
1 S: ]/ i) `+ d6 @# bcd D:\stock\test\source- r- b& I' e6 x4 J' v, d L9 E
- U) ?5 c' a ?' ?! J r" H
insheet using `1'.txt1 B- |+ u% r4 f
; L; Q4 Y4 X! A* F* L$ }0 M" ?7 q keep if v5>01 N6 x1 ]' L* i4 a9 _1 K) k
. [. A# @2 @% Q7 u* [6 V8 q9 V! d gen vt=_n& G4 m+ F( g: J0 w
% S/ {3 K, a" ?8 y1 P H+ Z tsset vt
7 u) \; O0 g3 m/ ?; ^3 r- [$ \, l7 q& \ L" s( k
gen zf=D1.v53 b( ~; H, E ^$ l/ H6 a
, [) i( f4 C' l# y) y
gsort -v1! a2 s+ g* q) d4 Y( A9 x+ g
; L4 a& b& n6 O* a# }. i1 [0 |# l
gen avol=v7/v5
3 l0 R! R$ q. A N
) B, ~; `* b/ a2 v keep if avol>04 v! ]7 [, F+ H2 r/ }) y
% Q: }+ a9 n' {* ^
drop vt
' N8 r3 [6 e4 V/ u1 V: l 1 y# E2 Y; V* [ U8 B# L
gen vt=_n
; h7 j \8 R1 Q# z: S( r* z6 U
& r; Y) R" K& _$ t$ X tsset vt
5 Q1 A* C2 S0 e, P' r' C
& K/ r4 f) P- w+ l) l7 f sum v5 [aw =avol]
1 t+ W6 V% w" M3 m
% w9 L+ R/ W& r) e7 O" d" ^' K gen amean=r(mean) in 1
. m8 |: Q+ K3 |1 B+ z! F
9 i+ B3 m9 ^* q+ B; m3 h. J * 总加权平均值 amean
4 u7 ?+ [1 }9 Z* c1 l M. h4 F6 B+ F4 G
X: J1 p) }0 F; ^, h
2 K. s3 K5 J' P* G( W0 j keep in 1/240& a1 Q/ B0 @$ i7 t. |, B ]
1 W# f4 L! o# n
sum v5 [aw =avol]
& C/ {8 e* j i6 F4 j4 U0 v; d8 N& q G3 v7 Z+ Y" Z) x
gen mean240=r(mean) in 1
& f; ^3 E7 i! B/ B% ` 2 q) P4 F4 B0 X4 g$ {
*240加权平均值 mean240
9 l9 C1 E7 C$ [5 E2 \/ q0 M$ E; R
q/ Q" Q, F) ~ set obs 500
& m% x6 m2 K) N8 y2 B) [( ~
2 [4 q4 o6 }9 r, j% H' s- x+ z kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
0 B2 P7 j4 z8 d- I; p5 `. k : Z0 A+ r3 @, X% O
*240 kdensity(dx240 dy240)* ^& M# d) ?# G& a- R! X; V
+ \6 B. ?# j6 C3 d sum dy240" e5 F( P+ ?0 u( h: d u& |* N
3 t) Q. g G8 N0 C, `3 n gen yxis=r(max) in 1
6 v. u; `, K! h- z6 a/ L
3 H9 N5 Z* J- ?7 O% p gen yxis2=yxis/2
; k/ u1 |; C( B* {: c4 m" d4 G
" i* ?# A4 a* ` *yxis1 |6 [8 P4 ~" k: L" o
2 ~1 R+ w) k# S' @
gen dy240max=r(max)
& F" o$ h* I& N - e8 d6 L/ r( X. `
gen dy240minp=r(min)8 ?: g4 m( W" @6 x+ y l* k. U) p
' B9 M3 j7 X2 K
gen vtt=_n
1 ^1 h& \9 _5 |# W7 [+ }1 l6 J- B3 u7 ^
tsset vtt- v& I0 Z0 p" T! F
/ z N; L) b4 j' Q) M) @ gen ddy240=D1.dy240/D1.dx240
6 c# k; `& ~( @$ N6 H , V% u% c" L4 r' h$ o5 l+ r1 m
sum ddy2409 i1 S/ f2 r' [& n+ \2 R$ i
. b P* E" ~8 U! F- I gen ddy240max=r(max)- T- i0 S1 q; s! \1 x5 F0 I0 U
2 m+ R/ C/ z+ E3 [# I$ n gen ddy240min=r(min)
. U6 y" ~ P) y4 j; s0 w* a / j- x' I. B T
gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)) W1 K7 ^6 J X/ a( R
) V) V( `4 b% k( K6 c2 j" y sum ddy240g
2 b$ ]0 Y- U5 x9 |0 U" h & |1 O9 P$ g; n" q- y% e) `" @
gen yxis3=r(min) in 1
; @4 |. n- k! h E1 f7 }
1 m$ W. r) c. K/ b0 s& ? gen yxis4=0 in 1: v9 r- p9 `6 J
4 Z+ z1 I6 T/ U2 \, V: y/ m! x
*ddy240g . C. I" J2 e% b6 o/ b8 Y4 [
: S4 Z/ g, w8 O/ c3 V, ?, g! R + G0 A3 e$ Y# [# Z9 s) i
preserve
% D# Q; F) t' G; {2 }0 L) @ 8 A r+ T. [6 T. K1 o% i# U# s }6 G( R. e
sum v5 [aw =avol]3 }! {8 \6 D2 G
. T7 n3 k1 V! Z' c; F keep if dx240<r(mean)
8 f6 \# H* s" r5 N
; f: n0 w2 x" v% d: {' k" E- q5 _# k+ v- V sum ddy2404 r# s. C* Y K; z# e G: ]
9 t, `6 k0 v# m7 E
if r(min)<0 {% W1 ~2 b3 k5 z
5 [- p. H8 i, V+ [; A9 U! S! R
keep if ddy240<=0+ g; ^) r6 l: J. z3 ^! Y
5 Q- n2 u; s4 c( q+ c& E
count
* W# H s4 A( ^
6 J U' w2 s$ \' t7 Z3 W1 L8 N2 A6 C if r(N)>2 {
w, x. O4 a0 V" u7 D) p
) J$ p! v, x2 h0 M+ t6 u- A pkexamine dx240 dy240
- W0 x; P9 I7 e3 I/ r5 b0 L
8 b2 Q" Y0 r. ]3 F9 T' v3 v local tempminp=r(tomc)
1 E7 L1 ]$ l) M0 Z g. l" F restore ( ~* p4 {* e" o" a/ F. P* a+ Q) R0 c
}7 p) p6 Y( a: l: d+ L3 X
- e& k H! \) l else {
8 k9 c+ P6 @% t4 I$ f/ x4 U0 q
/ s, L) k3 s8 x% H- B! \, E di "cannot find minp"7 O6 p7 F' V2 ^: R0 w0 p2 B# P
9 z1 U+ w( s, p# f- P7 S3 E restore
9 q$ ]; h8 j1 X, d sum dx240
+ |" |& h8 S9 N$ F local tempminp=r(mean)
, P/ }; `+ b# K8 E5 m
, ?. D) ]6 a& u6 R2 e6 @: X8 y }4 n/ {+ p ]! L4 `8 H% m
}% M: I/ |# ^' A z6 [
else {
, v4 G$ ^% {+ ]7 ?0 @! V( Y* J
$ j: v/ x# z, R8 {6 G1 K f* [5 D keep if ddy240<=r(min): O, Z" K2 t3 P- v" V3 y+ _7 Y& f- _
# n7 ?- x" @$ C sum dx240
4 R+ f5 f) ]8 u0 ~1 R# h
% I1 s' k8 f+ U# S! ` local tempminp=r(min)* Q+ X; h9 f5 k! p2 @* s$ i
restore
& a. b: W/ [* j }2 J2 R k; g0 c6 u! h/ _( D
4 d3 a% E) b; d% d' K' j8 ~
2 s* R* x3 `1 t& j8 s0 O' x
8 e( o8 }, t. p3 e gen minp=`tempminp' in 1, L* t0 m$ r% h$ ^
*240 minp
/ m! g" G# H4 G- U: \% I1 {3 N$ a0 n9 Z( ^, A& C1 W
/ O, `' @$ P& v$ [, n; u/ y
1 [( E7 ]: @5 E: x2 @! [! @9 D preserve $ {3 s9 B0 ] c2 V' G7 S2 t
! z+ U5 a; W& a( j sum v5 [aw =avol]* ?4 V9 H' j7 K, j( \+ p
5 Q+ P M' ]& ]) ^" c$ s( h
keep if dx240>r(mean)' [$ @6 ^" l/ y1 i' |) m+ D: ?
; X' ~# E4 ~' E Y$ k
sum ddy240
4 z! ?7 o* r$ j X- l; z5 ? $ k% V9 j* m- a0 q% M$ F2 I
if r(max)>0 {
! t4 J8 Z; {- @, V
* M @. O& F4 S2 E& x: O keep if ddy240>=0
# y0 ]" H1 r7 @0 ?& W. E. j, L& ] 8 L+ X! a Y9 o' _) R
count
0 ^4 g3 ^1 s+ D - F) F$ ]7 Z* x# \, c1 V, |9 E9 ^
if r(N)>2 {+ ^ r; |! c. I
0 g* u* E. d9 M" [; \+ p pkexamine dx240 dy2409 ^$ {6 ?' h O! E- C
" H) s; C9 {5 G) H. E local tempmaxp=r(tomc) . V- Y$ M. r7 J( p
restore ; l- k- T: d+ j: f+ s4 o7 d% D( d" d
}! y/ }+ j/ H$ g
# \1 M# u7 y! }( E+ [* ^- g ( S; Y1 @0 x# i: B( R, v
else {2 E. ^# b5 b0 C& Y& v
restore
3 l! ?/ g& ^( {: c di "cannot find maxp"
' H- J; ?& u2 Q2 v- x4 s 2 b$ L3 I1 g. w5 g
* S$ C4 F3 K: C" p' I C& V' ?* J sum dx240- C5 W, m) U' R2 {* |
local tempmaxp=r(mean)" ?" q! e# ]# D
" R. U$ \ l! d! z7 n( J) z* ~
}& M1 j- [8 i+ D& j" e/ {
( e5 X! K [: f* U
}- e" z- ~' V5 N2 m) q
# F4 G) ?( \7 _# b; Y
else {" q* K+ r0 B- i' @5 r
. E9 a0 y% f1 t- j keep if ddy240>=r(max)
, V% Z4 m( L6 [3 n+ o) _
9 y( P/ i1 \" h# B" } sum dx240
/ h% o1 ]: t/ m6 z
: F7 [- M2 `- y0 P7 A" U local tempmaxp=r(max)
/ S! E: a ]9 b, @4 K: {5 \0 H$ O7 J restore
# i" X7 P9 W7 E" N }; s& U$ E5 @8 j' m/ A' ]
* C2 V4 }. q* {2 y x1 b5 @0 S1 V. _1 z5 L, V5 U5 {4 |: b8 T. q6 d
. H0 B+ E' U* }- v
& C, x; b6 ~* c4 x gen maxp=`tempmaxp' in 1
) v% ~" v3 Y/ y) E- [1 Z. N i7 d
1 u* ] z6 D' j5 ] *240maxp
4 f; A5 b) g9 j+ i' K $ B Y& p' d6 T
X9 ~9 N9 E' g2 c9 f K! O
*-------------ddy240pminp左侧高峰值-----# {' `2 z5 w* a% l; }( m9 W2 K
2 `1 A9 V0 ?: x4 \ K' A ^ preserve 3 J' p+ u& s3 {) B
5 K8 N- `" t3 ]- @# I( o4 \5 {, x4 _ keep if dx240<`tempminp'
0 T' `$ w+ j! _. O* H. w8 d
% ~! K* b* S; f8 `% ^ keep if ddy240>0/ x2 X+ P% |1 B z% h1 \7 v3 z
, Z! v8 M+ K5 v* u1 @; I1 @4 T count
: z" w5 A+ Q0 e% l! b) q% g 2 q0 J/ d9 D4 O$ L1 h
if r(N)>2 {
; l+ W( t" `4 C$ }4 d' @# a9 }
" l$ I0 x5 ^4 M6 S$ u7 U2 ] pkexamine dx240 ddy240
( n0 H4 ]: }3 j8 x8 s . t; S$ z2 n- o! k/ ~
local tempminphddy240=r(tomc) . \/ V! F+ R$ E- { I$ G5 t
restore0 m8 ]1 ^* f9 U! A3 o
}
0 e S4 ?" S6 B6 B2 ?& P" { / v; Y/ y: S: K% g# p5 Z% y2 k
else {& U+ _* ]7 k8 Y2 I/ [1 \7 a
restore
0 Z6 Q9 @) L0 B5 c( o/ x C di "cannot find pminphddy240"; z% {1 Y8 K; c9 V
8 _/ B+ }$ V2 }) J: ~
$ p+ ?0 U, I% b( s) C T sum dx240
7 S7 _2 u) X B# @1 [; u. g local tempminphddy240=r(mean)
6 T: i B- A8 t4 m) A5 x1 L# O 1 q9 J! C. J) X/ U1 M
$ c# P1 K; ~7 W% K: o* g0 Y
}6 f* r( ]# C! A- ~' ]
4 \0 a9 i, U1 V6 X9 C$ u6 u) F8 O
; p) J+ c! K: T" {8 J: `5 B/ I; ]5 n
; g1 z6 m/ O# h 7 N/ O* t4 i z1 @
/ Q7 u% y& I' p! E% R4 R* W
* V% X! P3 a8 a; d, l gen pminphddy240=`tempminphddy240' in 1
: T: n8 z9 k5 `' X0 K0 c# ?
5 C/ T4 r3 s5 ] " t% v# z2 ]) w9 F$ o1 C4 c
*-------------ddy240pminp右侧低峰值 -----------------4 m0 u+ T" z/ V3 g( G
preserve
* [' j. F' f. N7 A2 H( ~ 0 g" Q0 g: ^! T& N
keep if dx240>`tempminp'
, I5 U( E" i# z- c) j S # m* v8 z/ x/ a8 b
keep if dx240<`tempmaxp'
$ v; o; u& b1 [ ^: y. ]" _2 j+ U, l
keep if ddy240<0. s" ~, _4 t( Q9 {3 z
( a1 p8 @2 \' K gen temddy240=-ddy240
& C8 V1 R" P- K% ~( R) c 8 l" d# h4 {& g P% P/ w
count" s2 `( z ] {) N; G* k, m
3 h% S9 u$ E F% L! o
if r(N)>2 {0 g3 Z9 E y6 l7 P) O0 h( t1 R
* x/ P1 I4 ^- G3 r& w% [) m
pkexamine dx240 temddy240
. M$ \4 i; w5 ]; m' q, G N % N- b. E3 v0 u( l
local tempminplddy240=r(tomc)
* S7 p+ P1 ~& T" S# c; X restore
& M& @5 n( r2 q7 g8 w7 U0 E- O }8 q- X; t7 c4 v
X0 |4 N' U" B& M! n
else {8 O6 o d( L) J$ A* [1 c
* I6 B7 c! n( Z+ \
di "cannot find pminplddy240") c0 ^. W7 N, l* F5 b z: A
restore4 b! e" Z# |2 @% N: \4 m" T
7 n$ l7 e% h# B0 w) `3 {2 Y4 y7 | sum dx240
1 Q9 Y) G$ V2 g0 a Y/ J local tempminplddy240=r(mean)
8 ?: r9 Y& l: ^) [
3 U Z8 M' l% x* O, ]; Z
) P- T8 W0 X1 e2 z* ~ }# q3 `% o8 v3 O) n2 b, m
% C; m, o6 H/ O3 q
8 N$ R6 l6 t( f$ ^$ j- F! n + L) v5 P/ V3 O
9 }5 E, i/ q6 @8 w6 J1 H: }
6 n2 \% ?/ k; B& t gen pminplddy240=`tempminplddy240' in 1
6 T3 M* u6 u: J1 i, |: d, w2 O * X7 F: I) _% I% U( T
*-------------ddy240pmaxp左侧高峰值 -------------------4 e5 H. |) J; x+ y* O$ \ x
/ j" B3 n7 T) D) k0 V1 A0 m preserve
( q2 e3 e6 X& N( a) ?% a' A& ]$ d/ {
* j8 y y" n9 A9 b+ n. V keep if dx240>`tempminp', I- j T; [3 C9 Y+ F
" X! e, q6 s3 ], i' |, i keep if dx240<`tempmaxp'+ G$ Y- H7 M+ t2 Z3 Z
2 I6 Y! R/ V+ n6 `
keep if ddy240>0
, R M' F' w/ r5 J8 s3 F; d count
. Y) T8 G8 {1 B+ K( `6 E / W, [% ?, a- d5 D
if r(N)>2 {; z6 b: Z/ R% Z" ?5 v7 w4 R
% ]6 r" a* ?: U, C" L9 ]( | pkexamine dx240 ddy240
9 l' ^- n; m0 C1 Q. J- Q 5 \( E$ p: T' U, i$ S
local tempmaxphddy240=r(tomc) + w4 G. @& }2 D
' ?* S( l+ b t" D0 ?! z1 Q* v4 j* h restore
8 {" X( x* j4 x! h; W }# j# I9 S, U* g6 d0 P9 J7 P
6 d. f6 c z& _. M
else {
) ~6 ~ h5 e3 r9 t/ t0 X " U" e7 w7 P# M9 D& X M/ l
di "cannot find pmaxphddy240"2 z1 ]" j9 t. L3 e
restore" M" J6 z2 F& H& {, R( W" X+ c# M
* _4 m @5 K1 z* o3 K. ^9 b# I- g1 ~# o
sum dx240
+ G1 k: t# g2 |8 u local tempmaxphddy240=r(mean) & f' C7 |& _4 K% Y! c' v6 g2 X
2 C# W+ e# I& N
1 V/ j1 a' p8 Y3 _) v
}
$ N" ]/ o5 l8 y) A7 e K4 B0 M
9 u% j3 X& }9 ^8 d _3 B ' f# m6 R" n9 C+ Q; B8 `
; [0 g2 L6 t: W& C- \ ) w2 Z, p0 p, x6 \( U
% y- h/ q$ d2 D" a8 b8 B
- c; Y# Z9 r7 J, k
gen pmaxphddy240=`tempmaxphddy240' in 13 H, ]# u6 `3 v' N4 K9 t
! p& ]* u6 @. w6 m7 R: N
7 F$ S4 m& [$ d *-------------ddy240pmaxp右侧低峰值 -------------------" l% B7 N5 l( s+ l
* ]; w! x$ U2 J8 e) z/ B1 f+ ^* Y
preserve $ R9 `6 o) k* ?9 C; f9 r/ ~
/ G: P8 q" X2 V; D keep if dx240>`tempmaxp'
; {9 M; S' F4 \' a' ] % ]* y" z/ b& A% H/ e3 F
gen temddy240=-ddy240
{" ]$ }: g* v" d5 U
& P$ O7 h8 w/ s keep if temddy240>0; W- S! ?' s; i4 G& }' r
: }' N: `+ A1 e" b% a8 y
count' Z1 e! H! w" ^
9 B2 ]$ I; d# r6 L" v+ Z, J if r(N)>2 {( O. Q$ d6 N* u& l
6 T2 H' M# }) q5 c/ U; X/ E
pkexamine dx240 temddy2400 e. _" {+ d8 A$ D9 i# P
1 R; W, b }+ ]! N" t6 l
local tempmaxplddy240=r(tomc) y$ ^. \) {) A4 k
restore( q; L2 g- `/ g
}! \# ^5 o$ }5 ~
0 k3 i& a6 h7 D+ ?# ? else {
1 s& ^% o$ h( X. I$ O restore
5 c8 B4 S# J f7 ]& X di "cannot find pmaxlhddy240" z& d) F0 _. c, G; u# ~5 T
9 y+ e }1 N; V* F* x
1 o" j* n$ `3 k! h/ y/ x0 N! q/ K! c5 D j
sum dx240% ?4 K# L3 m$ \( h
local tempmaxplddy240=r(mean) in 1" @! z& Y0 q. k! F& ^' g. R
9 h$ p/ @' c! L) {) y; a7 s/ e
/ J0 I+ {( c9 X; C [# r }$ J. A# N9 l( f8 V. E5 L5 t
y- ?1 C$ b; P) T
( c: g; @2 T' M7 l& | + @- c9 b, E( S: ^8 L
& L% }4 c1 J9 K
6 u% P& @. ~6 D7 A# r: w ' U' r! `3 l5 z Z4 C
gen pmaxplddy240=`tempmaxphddy240' in 1
0 p' `" Z- E0 H( y! U: `3 l
& Q9 N9 e) \) L *-------------------------------------0 t( O6 Q" q& c# A* r: g
/ h# v6 { B5 T* |! {- L H
gen price5d=v5 in 1/20
$ w; ?8 {6 Z0 \/ q$ D/ r ; [' g1 a$ V, q9 W1 h# S: l, f% v9 r
gen price5yy=_n in 1/200 y% t! r( U6 }5 S8 j1 r5 F
3 Z+ A2 i( e" V5 U) O* c0 [$ f) D gen price5y=price5yy*(dy240max-dy240min)/20
+ g+ c6 F o d
- k/ v$ c ^( Q3 [ *price5y &price5d
* |+ Y" h0 r6 O; g2 Y9 y( d 4 w" y! [9 C) R+ Y' H
gen priceny=price5y in 1
* w- W4 C9 Q+ c# z& X 1 D0 m K4 I5 w. l
gen pricen=v5 in 15 N7 l' v0 M3 v3 m6 j. T
6 m4 e! K0 ~% m/ H$ h ( R* |" d+ x) q4 h0 d" t% t! C0 o& H
*priceny &pricen
9 _" d3 Q' _- _0 l4 w
" g5 T5 r- _: {: x& j( H& j
: { b( V# ^& ~# a0 r5 ^1 Z7 I *-------------------------graph------------------
7 o. C4 R4 Y1 q- u3 J
' c* b' b; f; ^4 J6 n! Z 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) D, O6 Y* s" r- K0 \, o. e
1 R! O% o2 e6 P% U( n* ---------可选项目----------------------- ~% `" x9 H& }
*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean)), J; v ?! _# v! o1 V7 R+ o0 L2 v
}* D- n P7 P$ ^! j S) ^* x
end+ z" d9 u2 p Q, s- @% x* W+ x
|
|