|
maodeng 发表于 2013-1-28 13:13
) h$ ^" ~% x# K, l3 Z. hello 300236
0 R2 o, f% X' Sstatement out of context; }4 O7 b; S+ j4 Y. P, c
r(119); 3 d! ~) \& g7 ~4 L/ T
抱歉,最近太忙了
, j" X2 P7 d! k3 u" c
; Q, f W) J0 q0 g: T3 s300236 我用下面的程序试过,没问题3 F/ B$ P8 ?8 ~0 v9 Y0 s5 ?' e5 C
: s7 n$ C+ |4 A8 e
你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试* o- ~! ^3 k. m* X7 D8 E9 v
9 V, I% b, E# ^+ Tcapture program drop hello4 K B" E- c/ M% x$ C% f) M; g3 S
. G J* p& g: {5 A) j; tprogram hello
: y' e# ]/ D0 f! V( w& l' a5 n$ d7 Y7 z4 _- C- {# w0 r
quietly {7 l# L- k. ^' ?+ u$ M6 ]" u, |
" I- _& o+ v, _2 g) K
clear
" d* V J$ d+ G' D3 \' q7 Y4 g
: Q$ C; m4 N4 T: R1 v+ p0 A$ kcd D:\stock\test\source
6 m- U$ T3 C; {6 l% R/ U8 l* Z3 F& ^9 G4 G
insheet using `1'.txt
( r' t+ r) }! A% x: X6 F$ V: h ]8 f$ u& \* H- \$ Y) Z' R
keep if v5>06 S# m/ d( r- o: c. }8 ^* O. Y
2 L5 H% f6 Q% I `3 O8 W4 ~ X9 |1 F+ U
gen vt=_n: F4 {( M' u, k& c2 J0 r6 N# H) L8 Q& G; [
9 D! o& L3 o* L2 y1 K% y) ?
tsset vt- E9 P* E: u$ p" [! |9 s/ Q
* \3 m0 N; P0 f, b4 L. ?) _- U R1 o gen zf=D1.v5% ^5 |8 S/ j8 O8 V9 w+ x
! ` K3 j, L0 b' | gsort -v1
- m% F; l+ y! d4 h2 Z4 U# {' |) u/ i4 c# Q( M1 l- l# C
gen avol=v7/v5' G- R2 H# S/ V6 O& I" o
9 l- e, S2 Y" S+ Z keep if avol>0
0 M3 v' ?, @) d# [9 S4 F, v/ B " x# R% J; j9 R$ }4 w
drop vt
1 f1 k! S0 @- R' {( S " D5 ^6 d( w; c* y: u
gen vt=_n+ ?' Y9 t+ X R0 S. n
% t. {; L$ Z! a2 S% F2 o3 |4 x
tsset vt* E2 P: D4 l$ G0 h' m' b
2 y; O$ @' }% [" S
sum v5 [aw =avol]% w+ |' F9 Z/ L/ t/ e, n5 W, X3 _+ ]
" ~% S% _2 L/ g. n a* [+ Y( U1 }9 C
gen amean=r(mean) in 1
4 d5 I6 h3 P4 H6 w - u3 f, z k. F5 J' I) S( |: G7 B- Y
* 总加权平均值 amean
/ x% e- u3 f" j" q! l& N6 W
1 |" j( q" H$ w5 J# `3 J $ f3 S3 Q* _/ F$ K1 N6 I
keep in 1/240# ]. L# y1 _( n2 V6 P) X7 w
5 q# `3 b% ?0 }# `% Z+ Y( p
sum v5 [aw =avol]
3 M5 W; ^6 S# y$ s# X' [0 B
4 X1 p w8 p- r- Z gen mean240=r(mean) in 19 u# ?& [! L5 R; C! U' U; E
' f! Q# j3 Z6 u
*240加权平均值 mean240
) X1 f* x, w2 h( @
9 j" ~/ f! f, P set obs 500 . y. ]" w6 h t' T. Y. f2 c8 ^
9 O! n8 ^0 P$ z) o6 h N$ [- p
kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph2 X' j) O% c+ l0 r6 L$ h
7 S |# [- v$ }( C3 [% u4 o0 q
*240 kdensity(dx240 dy240)
1 A- r+ V2 P1 w- w y6 v% Y+ E
( ^* A& d; O5 U4 \+ r8 l6 \* H. Q sum dy240
1 x" a, P, e# ^2 G
& d. l% \9 t* n% u- G/ r' e2 i+ Z gen yxis=r(max) in 1
- O# c0 k2 h1 h& E' X! ^$ p9 p
* O. D5 @3 [6 \' }/ w+ o( E gen yxis2=yxis/2
9 ~3 p, M4 i1 q0 v
4 P$ S6 F% J/ v *yxis
( |+ p7 D2 Z% u8 v5 `5 I% O, Z : U# J ~' O# ?
gen dy240max=r(max)
4 [# ?/ B0 i6 l+ a
0 `% R# z/ a1 j& X) _7 K gen dy240minp=r(min)& @3 r0 s8 | o7 s- |
4 w* j5 L* h, Q& t gen vtt=_n& g5 W( Z* c: I
$ U6 a# m( K; ?7 a/ c6 r tsset vtt, B0 j2 h, E+ }4 A8 q& R
4 ^8 ?; [8 R$ M0 G1 ?9 {% l& T& } gen ddy240=D1.dy240/D1.dx240
+ u7 ]: U: k7 L8 W5 Y1 \0 Q9 t
9 W" ?* e7 P6 Z0 V! L) X sum ddy240
, U/ b! e# v9 }/ y# @7 J : n6 e. o5 [+ }, L+ @ `
gen ddy240max=r(max)
9 u1 C% [% M! U) x3 b# f 2 q: O& ?; O# \
gen ddy240min=r(min)
) Z7 W0 v2 ~5 o C' z
( f9 t' b+ i: y! R: s gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
* q3 J o( Z# } z3 U9 R/ Q & r5 @$ B- X( B+ B1 a
sum ddy240g. W9 h, ~. i m T# p1 K( ~
- C/ {6 T! @0 b: `/ [ gen yxis3=r(min) in 1
; ?, ?9 t% j' D, V 2 F% r3 n5 L7 `0 h$ N; ?3 X, E- i
gen yxis4=0 in 1
# N/ |6 r0 d0 g6 M1 T9 f
2 T. A1 G8 E6 W *ddy240g 4 F+ W; s( s; W$ Z
$ C! y C) t4 V+ {7 f! O# n
+ }0 o* p0 E& N* P9 e, V
preserve
O5 _5 M$ @3 |3 { 5 M7 [! T% ?" Z) w5 u
sum v5 [aw =avol]0 b" i( x5 o" c* j( |
2 |, G9 }( L3 ]$ y! Q& S
keep if dx240<r(mean): D8 v5 q" g/ _% M9 g9 ]- r* }
$ C$ b# j* q; W2 V5 g$ ?7 ?! L sum ddy240
, p) p9 r- f$ `% D
+ R- u- w2 {( f/ ^4 p if r(min)<0 {
3 V# M7 a4 l1 }# n& i9 p- s
6 v( U r Q0 E+ G' V+ V keep if ddy240<=0
2 Y/ v% c s; S* ^' p( R7 a 5 i1 O% t3 x; q$ b1 O8 v
count
, x' @# a$ }, Q( t' d " m* ]& f& \% L6 P+ s( q* c ^+ m- F+ o6 i
if r(N)>2 {
) i4 L$ O4 [/ V \ . |0 ^) T3 O( k! H
pkexamine dx240 dy2403 {/ N4 Y2 n+ |3 k5 Z' e
9 A- l i) ^; y3 O6 ~" p
local tempminp=r(tomc)
+ x8 O) X _; N8 a; @; g0 C restore
# k U# S; T8 R/ a( E* x7 E }
) T) W; z# H5 {. O, { 5 Q/ y9 I" n4 t( W" O: v+ S! f; [
else {
2 L6 W# {9 r. G- B0 L- i0 N
6 l4 L/ O/ H! N/ z8 l$ _ di "cannot find minp"
' B: A; p1 t6 N' W# H: ]. r# o# w: ^ ' m E' Z) e# \* j+ d8 Y$ ]
restore
7 l' v* K8 V# ~1 v sum dx240
6 {( \9 y0 A4 w local tempminp=r(mean)
2 b5 Q G# o" t" A
- ~- w5 K8 Q1 Q" b }
( i) {" p: F& Q) L" Y }
. q( Z j. F6 \6 I' S else {( Q' ^+ F4 P, b2 I! _
0 s2 X: H1 j; a' i
keep if ddy240<=r(min)
, S6 m+ I& }- F x! n# p
/ M. s. c$ L* t8 g sum dx240& i/ D( C. C, n2 y! ?. O( ?! K0 O1 U
4 Z- w2 }, ]4 e0 ]8 i! u
local tempminp=r(min)
5 W7 Y3 U: i) ?5 K restore ! z( {! {- ?/ ^: x+ F
}# S$ \0 {: A: i# I" r
/ [: r+ M# q5 R ~* f8 h y0 {0 A& p9 L% G2 y+ v
" [+ X1 [% B( v+ N+ A gen minp=`tempminp' in 1
( l) G o% v( f# Y! s& i *240 minp, J4 k" J, H9 _* E; ^
; O1 D2 J0 i4 B
( m4 m3 E* c$ ?5 [" O
& \$ r% Y; n0 X2 f preserve 5 h( r( t+ e. z X4 R7 @) ]
, J6 V3 r1 J' r0 S1 V+ l sum v5 [aw =avol]9 a# C: h" ~$ R
# _& a5 N- k; X# A3 p" f keep if dx240>r(mean)
! t8 ^0 h6 \( w2 K5 T9 A. w & y6 Z. u' z1 u8 ?7 O
sum ddy240
2 @# Z+ }5 C2 B* n& p1 q2 k g5 F2 q8 G$ y X
if r(max)>0 {/ z t ^ q+ W1 m
8 {' K7 R' i2 Q1 Y( C# U- z6 [. L
keep if ddy240>=0
: |' ?0 ~1 w) Y( {5 O8 O# `
5 A6 R; [9 u& K9 Z8 U& S6 `3 Q count2 A9 k6 v( h$ U4 m a) _
9 q, D9 G3 t/ M* P+ a0 i if r(N)>2 {: u# b% H' y9 S2 M
9 J0 X& B/ B+ }
pkexamine dx240 dy240
" N F8 x( n. A( ?. ~ 7 K' @) @3 j3 |6 Y* [
local tempmaxp=r(tomc)
/ W$ z+ M. L6 {5 C | restore " p4 g) s' C2 v
}8 V) r6 ^. g9 j3 @2 U3 P$ z+ R
0 z ?& V7 o. I$ D' [& d5 S9 V4 ~
% m# ^) w! O6 [' u5 m& v, E$ B else {+ A: a* ^' a* Z% W
restore 7 K0 l( B, O& c6 F4 x$ K
di "cannot find maxp"4 I+ N e6 L* W ]. C
% z7 F! n2 X' h \5 w0 d
! i' o- D8 q& e. F; v6 h
sum dx240( J. {7 p/ j. {7 @: Y/ ~
local tempmaxp=r(mean)
; Y0 Z- V9 A6 K1 p 3 J5 M; d2 c" g- r
}
5 r: n) F0 r$ r
; u, p' S! y1 R' {* O# M }
$ t4 z$ T* n W5 b7 T2 J- y
$ q) i5 G* ~5 J2 ^9 T' z2 ~1 c o else {/ m* U! l% d6 y- [
2 `3 V. X$ }- L0 o" I keep if ddy240>=r(max)
7 a$ q# I- Z3 V$ l9 g( s# {/ Z1 j + X1 q: E" z; M% v; h- O, |
sum dx240- h7 e: P* e' [: N7 X# p& x
* k4 @6 s6 L( K" `9 d local tempmaxp=r(max) & K: J8 Z3 N, c
restore , G0 n* [; I+ D z, g( X
}
* x. ~$ _0 L% U6 G/ `: m0 ~ 8 X) I) `8 d1 L9 {6 ?
9 i! Z8 J2 E/ z3 o7 D$ H2 j, c
/ v0 H) G$ [$ N4 Y2 B
$ m Z, B: O% M# z/ k gen maxp=`tempmaxp' in 1
) j% A& f, D' o, J' S( {
0 U& G8 W' N4 R2 R; z *240maxp- q* W% _ i0 \+ D% o1 q
5 t5 N# E& h$ F7 t; F$ J, q* R9 d$ c% w1 n9 K 2 ~9 E6 K; U1 @' L) H& u* f4 e
*-------------ddy240pminp左侧高峰值-----) z6 Z" i4 ~! |2 m
! S4 |1 g6 t3 U
preserve . n7 b4 C" r) W( \ ]2 G
3 m, q) d3 n J keep if dx240<`tempminp', ?6 y. j! G5 U, B2 H ]
0 i5 X; _2 y4 _6 D! Q keep if ddy240>04 Y# h! [* V; E
3 H3 A! k( Z9 s
count+ i. z, H- |& t U; o, q
, N9 p: }, M4 E
if r(N)>2 {, q: R9 o" F* U7 e
4 g" |+ w8 E" u% F! D: t
pkexamine dx240 ddy240
. D, U, Y! |3 Z, V( @1 q* H: D! _! x
" H/ e H- l7 ^1 B' }# T local tempminphddy240=r(tomc) , p4 m8 t$ o; p4 J
restore! a6 d7 s" b2 o8 M Q2 ]1 W6 {
}* C$ u% m B; ?0 A) \
7 D2 S; r1 Z+ u2 J6 Q' j! k( C
else {
2 z7 q0 |, B) H5 V* o restore 0 ^: g9 q0 C$ f5 K/ d
di "cannot find pminphddy240"
# r( D+ N1 s& p" y9 a
" m+ j) b# Z1 Z+ z1 }# K9 I* a
, o! \+ Q |+ g a _ sum dx240
3 b' [2 l1 o+ H local tempminphddy240=r(mean) / l! a% |; o( z
3 x. z1 i F( @2 w+ T
. _2 g S6 c5 h' r) N: J6 G/ N }# y, q" p/ g: l4 s
, |) r& v' I; t+ c( D- E ! [6 Y5 J* I/ E/ X
6 V* O& w7 A8 _9 L0 G# g' {. o
' L" i4 Y0 g' L$ f" w U " I# w; L: e i2 k) @9 O
* l7 m! q0 Y7 s2 b
gen pminphddy240=`tempminphddy240' in 1& s; J' v9 `& e+ N' N# u2 ^7 w
; i9 R |2 A+ Y5 B
3 z3 B9 I% W3 Z *-------------ddy240pminp右侧低峰值 -----------------
; k4 f8 a) ?5 z K: A preserve
/ b5 o' h7 M' h/ N- N( J: ~ 4 c0 e. g. p0 R$ S, N
keep if dx240>`tempminp'
( A5 v- R! \7 M- p
" D, j+ k5 v! W2 j, K0 t- F! _ g keep if dx240<`tempmaxp'
- p8 p/ ]2 X) P# J- v ) _9 U4 D; ^9 C3 J
keep if ddy240<0
; Q9 J2 }$ Z/ B8 j2 H3 S 4 v, r: L, j3 D5 ~
gen temddy240=-ddy240) `( t% K! _* }: N
4 h3 D- B7 }& ?; Z, M1 L# f+ t9 z
count# X: u- k& @ `* S4 B# D2 x' r
% U- U% i5 I6 M* v9 N; ~
if r(N)>2 {6 @9 I+ @4 r( T# ^
0 F2 Q3 B$ e# m& h pkexamine dx240 temddy240
5 Y" Y# h" l4 q: _8 e
$ a# H& |$ J7 I6 I% @ s! | local tempminplddy240=r(tomc)
& R' S- ?' R6 v: \/ j) _; X) | restore
" v2 t) e: Q" q, K9 e( ~& r* t }
- ?8 R @& b$ {& J
4 h% C9 {& C" B; j else {2 ]2 U6 p; D' ^1 J
7 t( Y z8 H0 H3 i- t( M, V; Y di "cannot find pminplddy240"4 k8 c4 U4 b9 M2 [4 O1 L
restore+ j- E) \# x) l, }: N: F, P
4 C; `5 K- S* k9 I. A$ U: ~% I: w( A
sum dx240$ m$ h( Z' |9 M
local tempminplddy240=r(mean)) U# H. x3 g' f }" z
8 s+ K) b3 A, j( Y/ r' ]# K d3 ?
* r' P& j ?# g8 o E; J }
' Y; V( j4 ?. E$ H5 F# }2 X+ | $ Z1 N( z1 W1 ~: U4 L
% \+ e- p8 @% F, x8 L* L
9 V+ g6 V6 x) g4 t( |& C 1 b% P6 G. Q- `- z5 E
: r8 `. U7 j+ W9 v gen pminplddy240=`tempminplddy240' in 17 B0 i7 {( z: D1 Z9 ^6 f5 r
Z+ Y5 t" y7 [2 d
*-------------ddy240pmaxp左侧高峰值 ------------------- w$ a2 X8 Q1 @+ m
; g8 K' F: j D3 b \1 P
preserve
1 U d6 [5 s3 |5 x . g" W, T( `( V$ K$ Z& j
keep if dx240>`tempminp'
6 ^4 h2 l" l9 i& Y, N$ Z
% r+ g& r0 Q6 j keep if dx240<`tempmaxp'
& `* M% o6 ^$ I
+ L' Q0 [, ]% I7 q keep if ddy240>0
, z" @7 k/ O4 d+ p8 ~ count
7 ]" Y) _ a- l( \6 C
# s7 L1 c4 c1 a1 H7 P if r(N)>2 {
5 S) A: k" H9 `
" N3 w/ p4 _; [" p5 @; z4 ` U$ `7 c+ e pkexamine dx240 ddy240) N7 R: b; w2 u) I% f. w# y E
2 X. F% A% g! g( O' ?3 N6 t0 E local tempmaxphddy240=r(tomc)
; L" f3 I2 x% `3 l2 A
! ~: ? u: h9 @ restore
* N' t) m: c. ^- G. [' |, A }
3 }! `+ P6 l$ J+ M# ?9 G9 z& J9 [ : L/ d4 l) E9 ]# V: Y
else {; p1 v3 J9 L+ a2 n) w# D: I
4 {! ?& B9 u6 s di "cannot find pmaxphddy240", S* A! W! L6 n c5 s' F
restore+ }8 N" L S1 X' h" l: f
" _- `+ u1 }; E5 L
sum dx2406 N$ i6 g' c& K: h; P# l
local tempmaxphddy240=r(mean)
: D/ x( J: P0 R6 X5 ^3 D ) G, a, ?, u' v7 Z7 H& G. `
% i4 v' [( q$ S# c }) h# [/ c. I3 h
. A8 @9 |' a A
9 [/ ~4 A$ B$ Y! Y; e " {0 @ x2 z, h9 H E
$ g/ u% t8 Q5 ]$ N' {- u# |8 u; K2 c
5 G2 U" I2 E7 \% C4 a' W. G7 ]
+ [$ o2 V+ V7 s# Q$ [ gen pmaxphddy240=`tempmaxphddy240' in 1
# r ?& h4 A' j9 J% `, K # V$ A$ [* o( E, Q7 J
; `* S# y: e9 U3 D) ?" ]" c% t+ Z *-------------ddy240pmaxp右侧低峰值 -------------------+ ]2 C8 [- b2 F7 ^1 e
$ i& p5 q8 h" g- F: T$ h
preserve
3 m v5 |5 M0 z( ~) h' d
; k, y. z* H# ~9 m; b" o- N5 K keep if dx240>`tempmaxp'
3 h) O0 _# ~6 M2 N) d ; K! m! i4 T3 _! a1 X
gen temddy240=-ddy2404 i3 ?3 o1 B2 R6 {2 q+ t' @8 j7 z
1 b9 O" J4 O7 |" f1 V keep if temddy240>0
- ]3 H# `5 i, h/ `, u
7 p, T6 R k* e8 H6 ?/ R count/ c6 j5 Z, j! ?0 e& s1 q4 O
8 z/ g: T' m" G2 R' C
if r(N)>2 {( s! o/ l o# t3 B z
. S7 M$ U0 z1 O+ S) O
pkexamine dx240 temddy240
, u! Z% J6 S4 U+ g$ c' E$ H . [: H3 f/ n; H# Q+ Z5 v
local tempmaxplddy240=r(tomc) : N6 o1 v9 G% E- @9 j6 J1 c" @
restore
9 U; o- k/ H- C2 e }
$ Y1 N- M$ @$ c/ p6 t ' N9 H1 P L5 P* g8 @6 m
else {/ F6 O3 b! g7 B$ K" d; B9 x' n
restore
2 i$ x+ P* V% w: H8 Z di "cannot find pmaxlhddy240"5 b0 `+ G5 |* J$ m
6 z- K- C& W, q/ ~
9 A8 f& r6 y2 F sum dx2407 R/ u7 z' A% i8 ]
local tempmaxplddy240=r(mean) in 1
5 ~4 B# a7 R% l1 N4 j
/ c$ {2 U+ J9 \: d3 D, `1 ] % @; G$ @1 ^: t$ h! w9 t
}/ z/ W& F0 g8 y, O4 z9 }+ V
& Z! @5 A' s/ b F, Q * Y$ J% y. u: b7 s5 p' ^% f" D8 _
. a$ A3 }0 o( U# Z
7 ~$ t! u+ s% }( ?, s' H& t * O6 B) N8 e; d) o4 ]( E
) g7 w( ^( \1 { V0 z9 c gen pmaxplddy240=`tempmaxphddy240' in 1' X) w P: g* \
+ {7 @/ s( M& D- I- T
*-------------------------------------" m @ a+ i2 D" D3 I
/ ^2 X3 d7 w9 u3 A
gen price5d=v5 in 1/20
4 t4 `" }# w% k1 Q$ S 8 H( D/ g: p6 O
gen price5yy=_n in 1/20 F0 k1 v2 }9 C# `
- I: J( t, d& D- ?* H gen price5y=price5yy*(dy240max-dy240min)/204 y- u' L& Q- n2 A; e
! x3 ~% }9 K4 L9 y7 M
*price5y &price5d
8 ~, X1 \ h8 p5 G! p8 l2 ?; W& c
" O6 t) b! E3 ?, u- M" P$ o) X gen priceny=price5y in 12 p! a! R4 r' V& [. \
5 L+ D6 v: f3 U5 _% I gen pricen=v5 in 1
0 d: u+ ?: b) q1 X3 } H( H6 v/ b+ p% B5 Y, w+ B! f
2 \ Z" l0 t/ W8 |' J
*priceny &pricen) r) x8 I* U) E. W U9 z) m2 I
$ V: I9 o4 n3 r9 q$ g7 u& g
+ V# ?$ A8 q1 L. G: \1 ^8 a; F
*-------------------------graph------------------ t7 a2 y) } K
0 z3 J4 }! J$ \7 n5 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 ]3 S8 N* z9 ]+ |1 w$ K2 w+ p/ m& S s3 r) B# M
* ---------可选项目----------------------
" u- l9 _' D7 a# ^' B! _*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean)), l5 _. N( r* o; `" U
}
1 g( d. n% [1 e' e e& tend
) A. t$ \. I. t6 g |
|