|
maodeng 发表于 2013-1-28 13:13 # _, t$ ^8 M2 W8 L7 P: C+ `
. hello 300236! |& l* ~; E, D: [" B/ P j6 [0 s
statement out of context
) j# U$ _& [! x3 i% vr(119); & B. X% ?' x& c8 i* B! y
抱歉,最近太忙了
3 H" N4 G& V J; B5 i7 [
" J! y" }$ I; z300236 我用下面的程序试过,没问题# l. D9 d I/ V& s+ g* J
/ q6 v0 I2 g' c& R$ q
你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试
4 X. E+ V1 n: e1 N% N5 f2 H, v4 q2 u& ~7 ?% I$ U' t* i
capture program drop hello$ E7 m! {( }5 Z$ Y/ M/ I7 g
! f0 ~. h7 r: `$ T. Z7 Y
program hello% I3 `2 i, D8 E- a2 G1 t( j. b
' c2 p3 V' X9 d6 v. U quietly {& O# M I7 ^8 l% G
4 a3 U/ r2 P+ D& ]7 r+ e, F
clear
: s/ K) t9 w1 {) k% R+ V' K8 H7 d0 c) w4 T
cd D:\stock\test\source0 y9 Z/ d4 \) F% ]7 {
2 U9 L7 O v/ {$ l# Finsheet using `1'.txt6 P8 x* [1 {/ D4 y( c. D. C
& x8 h& N, }) ?& ?( H" @9 H; i
keep if v5>0
- Z" c, s; x# A# N! Z# Y% J0 H; z " i# L( h8 {- R1 b8 z4 E5 [
gen vt=_n
H# S5 { d. U( U$ N- z t+ X, N: {$ p& _
tsset vt& R* F2 M+ g% B! K( j, b' I! b
8 \: V. |9 ^* J0 @6 E4 S' }& t5 p gen zf=D1.v55 t4 N9 U; q& m& k) G
0 a3 p, S6 k0 {3 ^) Y! _ Y gsort -v1/ H+ _8 s5 y+ y& O4 e
8 ~+ ~: X/ u- d
gen avol=v7/v5. G9 a' D9 h. i, ]8 z
7 O$ k, x6 }4 S# t; i keep if avol>0
1 D& \9 D6 Q5 U
3 h2 b( O6 A+ b( {# E R drop vt
9 ~0 [0 l* y" D- W
7 b, I# s- Y0 [7 z } gen vt=_n6 ^' y* I$ L* `/ [, w$ d/ O
, g4 D& ^/ D/ V5 t" a8 e tsset vt
/ O. t3 q4 s/ k" v9 T6 i) `
2 A; E& X& L( V sum v5 [aw =avol]
1 ^' H3 h+ P' s6 \2 j
1 X; F4 v( {8 ]% Z gen amean=r(mean) in 1
; W& [' Y! |. s+ Y/ a5 J 0 L( N, x% ~% F" G; ]( d& U" q" G T. ?
* 总加权平均值 amean
. R" T- L* P: z; E . C! o7 ]! t* |0 b
3 L; D2 o0 b# O7 \! [ Y
keep in 1/240
( V$ C. z* ]7 p) ]& [
" Y5 Q3 a% K2 K, i" e$ T8 E sum v5 [aw =avol]
; W, }1 r6 W/ u8 k. E8 [+ Z9 b0 X6 ]" a2 T
gen mean240=r(mean) in 13 F( j9 @+ p4 g
; A2 ^9 r- o& G- c *240加权平均值 mean240
% v4 w" c- s/ \* G- V9 x 3 D8 D! q; v! P/ Y' b
set obs 500 7 F' p8 ]8 z$ z+ H" J: E
, t- U9 @4 ^( a
kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
" B- g) B7 b% Z
7 w* I P# `3 \( Q" E *240 kdensity(dx240 dy240)0 e6 V4 u7 R' `) e; [
5 ^3 z) n0 i$ l5 b* M2 z+ n8 @ sum dy2407 W/ W9 y/ L% r) J6 C! s
: ?5 i U* p: h' c
gen yxis=r(max) in 1" v- g, F; ^+ X6 _3 M7 N6 o: I9 T
) T$ S" y5 V8 {& d% E$ t gen yxis2=yxis/2
( N9 D# x- T; S# E3 v& h# l$ o % F! u0 f" A, t
*yxis
4 @( p; t& F4 y' E8 J
' C0 i! J8 t1 Z! O/ j) n gen dy240max=r(max)6 z! s7 V2 c" Z$ I, k# A
: t- g( s) E; g gen dy240minp=r(min)5 r% n# H- R5 W8 ?) ]. K
1 q) H& w$ n( N: p# F! m, b gen vtt=_n0 e2 h1 z* z7 h6 O; H1 W" E
9 S2 C, W+ w& ?' B$ E
tsset vtt
1 T( z/ r- k+ P9 Y/ c
, y! Q. X q. @ i gen ddy240=D1.dy240/D1.dx2406 g j( h4 C1 @* E0 x, s
6 y z* p/ W5 r5 F7 @1 P
sum ddy240
. L" K* Y& U2 @ m+ [& J) C ) [ b! V+ H7 Q" \
gen ddy240max=r(max)
/ y& c% j) S+ Y( u- A; ]; p / P m: B2 g9 c2 x5 x
gen ddy240min=r(min)
' P( O2 V1 C% A* U9 c
0 G9 x/ o: M$ s( t. \) L3 B" O5 Y gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
- q! ?$ _( ]) f- c( r% M* F
& O R' l7 J2 c* D2 H" C sum ddy240g
% |5 r% R3 @% g2 s- n2 w7 _+ _
% S: }& |+ P8 M7 W- V) E gen yxis3=r(min) in 1, n/ g! ^) m- j! E/ p* z! U
; b0 k2 x8 L' o% M3 t' |. }* K gen yxis4=0 in 1
5 m; B3 g- N) R7 l4 Y
( q) i: B: H& a/ f. j- d *ddy240g ' M5 _$ Q# ~' m4 O* o! K! B
7 N/ Q7 M# D8 s$ T& @
2 X& I! C. J" O# }
preserve
6 o4 l: x$ W6 c- \3 T9 S3 y
; }8 f ~' P* y g! O sum v5 [aw =avol]4 g$ @. L) e* a+ W3 H. o
, ?* Z9 O6 O6 O8 I# y% r" I/ k: z5 @
keep if dx240<r(mean): n8 l3 l6 S4 M O/ c& y$ G$ r ]
% L$ \# ]! A ?
sum ddy240
% m+ X4 t0 I9 |) c9 C% I: |1 x- b 0 b. s/ s. e, C, d1 _
if r(min)<0 {
7 T* o) L# I4 b+ i* W1 o8 C( g- v
% Q# k$ g0 |$ V3 b8 \. o" q3 A keep if ddy240<=0
+ V+ _! g, B) O9 L" I" ~ - H v$ G9 W; c9 _! m
count
m/ I/ w6 Y, @* s0 I: f 2 B9 K+ _; D! |1 W
if r(N)>2 {
+ a) G) t7 \0 |) e; [3 R/ s6 F ) p7 C, c5 B( O/ M! ~- E2 M
pkexamine dx240 dy240 u" D# E o5 D' @) F; G
$ F; V e' g. t: s) v0 [9 y9 y
local tempminp=r(tomc)3 a f9 ~9 `: `( ^6 ?: f) ~
restore 1 |5 _* E' K9 g& \+ f: f
}
) L$ z) W }7 o" P ( t& p6 P8 a% ^
else {) m3 u6 z5 {( O( l# o
1 t+ N2 N- e R( u+ x% B
di "cannot find minp"
: V8 O9 b( k% e* p8 y/ z' P% T6 i! [ / Q4 f r2 K; h: `$ x* o
restore 2 ^2 y- ?. l3 T
sum dx240
* F& n. ]: U+ |3 b* u4 ?! i/ f local tempminp=r(mean)" D+ ~: W+ o0 b. t/ J; i
7 b) v1 |1 G# Q* j
}
) [ N# @5 X t f: R8 u4 F# p5 k; h }
# q+ a, K: j9 ^' d- T3 h7 P else {
$ k7 A# B1 \" `6 `; ^ $ W# d# [' j7 E
keep if ddy240<=r(min)
& I. C0 y- z/ M2 M9 W. N ) @4 }- {7 e& `7 J" w. q
sum dx240
% W: b) a1 W& N B$ z3 W
9 G: m% n8 s1 Y- w6 s! i+ Z local tempminp=r(min)
3 v/ o( P5 V" O9 m0 Q0 ? restore 1 m8 y( J9 q9 O4 K: G/ U$ a0 e: r3 M* l
}
( i5 U3 I$ ?( V- h* }* K, i- U: O6 Z
; h, c4 {. X' g0 ]2 T4 w' @, Q7 H% s7 l% k$ _; Q# O [
gen minp=`tempminp' in 1+ R' ^% h( C+ H. }
*240 minp
+ e* g' A* l+ V* j- n' G/ P' J6 s4 r) K
/ e l0 O- E# x3 D; u$ B2 s6 t% \4 [
0 P0 j$ @4 Z7 i. `2 d: W preserve
2 t( Q8 I& Y2 Y$ A4 w9 o$ h 8 C' [) s2 U; t: T1 [$ {* h; F
sum v5 [aw =avol]
8 _# o4 a" Y+ E: n3 {1 l3 L6 Q
; ?. n* N2 H6 l' b7 X keep if dx240>r(mean)) k% @) f% j3 g! W6 \
L# g! f2 `7 s: X9 ~
sum ddy240/ A7 K/ V% w" c
- S' ~. _8 x. I7 x& t3 ]8 m if r(max)>0 { ~6 R6 U( K$ d1 J) h' ?
) y7 i$ W8 h6 X( N0 U keep if ddy240>=0
D1 Q* q& ]6 N 4 P2 d" ]1 a% s0 Y& f
count
6 T6 T7 M) k% ^. s6 V
; D: ~! \( a e) h1 s: c if r(N)>2 {
7 ^" n! ^' b% b: w9 W. X+ \$ [ 8 w+ |: B% F5 E1 k# k
pkexamine dx240 dy240
/ D# _% q5 |% y) @& G+ z5 T& T 0 n- ~8 k9 S) {6 E7 N3 R$ `
local tempmaxp=r(tomc) , T2 a. J7 `: _3 l/ c2 }
restore
: I6 F }4 j+ W A' i4 ` }" n2 b4 A! A& {3 t0 M& y+ c3 l- U2 y
: Q3 }4 q; j [$ M# B, E* X ( n4 p2 v- m3 h$ B& x
else {+ C. ?# @. e3 D' R
restore - s6 `3 |' s, [8 o3 g2 [
di "cannot find maxp"% D: i- q7 P0 U! s0 P A
+ v2 m# ]; M$ M, N
$ h: B+ d/ K6 @# `, c sum dx240$ y* A0 W( }6 N. i8 Y2 G
local tempmaxp=r(mean)
. F5 p q" L% j% O ! c0 \) i7 t. k; v
}8 `5 m1 c3 k0 c1 w; A% c
" ^5 J5 S) G( Z
}5 M- ^- J# l9 b4 C8 Z
$ y6 A( H9 x# R1 a else {, v0 u) q( O+ k9 v8 q: v
& c- l3 w9 R: P3 `' ~7 ~" n; j% u
keep if ddy240>=r(max)
/ A8 b' r5 k: K! ~& i& o
. f! h* ?- q \! H/ q& a sum dx240* g: L9 u6 r/ f) Y; \3 o
( F( }# |8 D/ g1 f. D
local tempmaxp=r(max)
+ A8 h& }( n/ {: s! m restore 8 R2 s) Y/ d' _' x& t4 [ e
}
, E# y! g! g) V* Y4 G# ] + l0 ~2 H7 F' x
1 a# r/ r1 b; ^$ p2 n 8 c4 Y1 D' v f
. z; Q1 ^+ D7 z, b" C, Q
gen maxp=`tempmaxp' in 12 [) d( Z" z- |7 P$ z2 @
, i" G0 P) f7 a& r. p5 Y( z
*240maxp
4 V/ o- n. ]4 X' P5 ? 7 @$ V' D( E/ l( S
+ C4 x3 v$ E- q% v; N' A, d$ }
*-------------ddy240pminp左侧高峰值-----
4 W+ F. d+ f8 X0 A 1 }! D, s. J9 _; W" p5 ~: ?: i. ]
preserve ; ?- N: ^1 r5 p% A0 O
% A: u0 `+ X! s1 ^# |7 B+ ]6 N
keep if dx240<`tempminp'/ N! x9 l" r- k3 a9 T* z
# T0 g% g, K; j$ d% P2 U( \: X
keep if ddy240>0
0 p, F a: h: r$ ~2 E8 l$ ?6 \
$ S7 [# \3 j$ p8 ?- p& H count4 T) {2 V! F& n; K
# N7 l# ~' J' ^8 t+ D if r(N)>2 { b B5 u# n/ t, e5 }; X2 h
7 ^# r5 `8 L% T/ t pkexamine dx240 ddy240
& J' m& Y' z% h; A2 } m- j( |9 O
8 _. U0 m, G# I$ V local tempminphddy240=r(tomc)
- |9 B8 I! ]8 E9 e1 }" a$ I, ~% L1 a% G restore6 B; j- _: Z7 @
}
/ y& M$ E: r) K0 J7 V T
. r1 u) \5 D" e% c% p W else {5 e6 H% {; O; Y8 T Z* x4 b
restore 4 R$ Z0 m4 u: m7 B9 \7 ^9 p
di "cannot find pminphddy240"" I% p2 o$ A! L) y' t' U
& g* E# d) S0 p3 H& ]8 J+ q4 U . o5 c* C& D0 Q1 v
sum dx240
7 O4 S( @4 A( Z9 c/ e local tempminphddy240=r(mean)
6 W& j1 j7 i) M a' K
8 [" h8 s: ]: s& | ) @7 f' ? T Y) a% D, E
}
# {8 z+ o$ i' u 8 v% ?' B. L1 m$ I) d( @( r
# P- R/ E( s% h% J# Q
1 H3 ^$ m. S$ Q7 U
: k) B$ ?( W$ h& _% _6 E6 H ^+ H
' C7 L0 `& @' Y! W
. x5 T _1 t" G/ j9 s+ c gen pminphddy240=`tempminphddy240' in 1
2 K- F* P. S; y7 j- c, X. C. E/ c 2 s. w: V: q* t3 Q5 i
5 K+ N6 ^) b5 Z. z1 S: d
*-------------ddy240pminp右侧低峰值 -----------------
. A& ?+ T' k* V( a preserve
. f$ J2 n) y3 X& K
1 a, }( ]# w) I keep if dx240>`tempminp'" d' Y: Y8 [' x7 e3 D* Q' X/ f5 b
% J. ?8 _# e1 Q d6 |0 f keep if dx240<`tempmaxp'7 {7 k' M0 w; ?7 a" W" B# o
7 B( n7 i% g& ?6 \9 E4 w
keep if ddy240<0
+ k/ q$ Y3 {; t' ?$ x
) Q$ C% g/ i( l7 f; j# A gen temddy240=-ddy240
* [& R: T0 ?! N) q: b' S8 c: v, L
' F4 [8 @. R5 L: H) C count. M, t: e" a. E" ?
) L5 t; v4 e- Q6 Z0 A2 y if r(N)>2 {- e5 ]- U# s8 ~& i C; y
# @3 g' g9 U2 k! Z; B
pkexamine dx240 temddy240
3 o: w% l3 V9 H4 S( @7 `# |
" Q8 r; k3 `+ w8 ^ local tempminplddy240=r(tomc)( b8 o# x" W( I, Y9 w" D
restore
: r- U3 h( g: U& V$ n# B }
( d; b! b/ x) w1 J. O3 n ' D3 Z2 m) V! D3 h
else {$ ?- n. W6 T- p
* ]; W _3 `( o2 A% T1 [ di "cannot find pminplddy240"
* t( ?* q4 U( R. E7 ~- v' U restore- L9 ]' S' x5 G
& K( V7 U( ?( C+ p7 Y sum dx240
+ h0 K% n9 |+ ^& E8 @ local tempminplddy240=r(mean)
* X& }3 g; d1 |. j; k
7 B9 h0 p& u$ W- _, J: O0 l3 \$ r : N# I$ a1 F7 @ A2 e
}0 v4 S7 b9 Y# T2 a, j# T
' W- ~8 j1 u: v" B1 [# e8 v ?# d" I# s; m: {8 F: j6 |
0 A- q3 J) @7 T, M# f
% T' Q2 q. L1 j0 w1 M4 ]+ l. C! D8 w
' Q% k5 J3 G8 ]; _/ h3 U* c gen pminplddy240=`tempminplddy240' in 1: R# l2 N, {' A3 O# Z
$ M- z" H/ D# @$ z% s& }0 z *-------------ddy240pmaxp左侧高峰值 -------------------
; M2 A1 }/ p! e2 p7 [ " A. F7 }: N4 c
preserve
6 ?& E/ m! z/ Y; `( a+ F- [" z! A, S5 }
/ q. Y* M1 W( H& ~" G3 l5 K keep if dx240>`tempminp'1 s" V6 k/ N. G& m9 [
3 v; {0 O4 b- |! D: X
keep if dx240<`tempmaxp'
" ^. N! V; w- g* x) s
* ~2 b8 d& L4 _# t keep if ddy240>0; `- P- ?6 }9 B6 Q* E7 n
count
: J/ w2 v) h; p3 k) S) X
7 E+ k2 R) ]6 ^$ \9 _' r0 K1 h0 w' \7 Y if r(N)>2 {2 B- L& o& V2 @% \
5 _& d% |0 j' S
pkexamine dx240 ddy240! K9 E4 y6 v% g( y) w" V" \3 N% Z
$ i7 K2 R4 j2 h/ b
local tempmaxphddy240=r(tomc)
7 E+ F( w' P' t, j3 o+ b 1 f' _. a0 _8 `8 u5 {' r- T
restore
1 k, g Y% A# Z }
) ]3 z0 n8 O( V( C/ p" z/ q) ^ 2 a) I2 [3 i. w+ k# d! s0 c
else {
2 A- _( z& D& ] . ?) C X- Y; D& n3 L
di "cannot find pmaxphddy240"
/ ]; T0 e2 d' Z restore
c) N, t* b ~$ G 6 e b E- _4 V# \7 Y1 T& A( C
sum dx240
! T- n7 ?/ H8 e) B* |/ l# ` local tempmaxphddy240=r(mean)
) E, O0 m/ H' W# G4 C. @2 I
5 ~& r3 S3 s8 S% K: ^ 7 h; a5 s; O; \+ b$ C1 L
}) M, s: ?/ P9 j. m! j: O
- ~1 C, \$ t6 g+ p6 V# h! k
+ E8 C+ ~: R9 ^4 \$ q6 n0 I $ Q& Z( t4 \5 m) E+ O
/ V4 N- j4 @+ |$ k ( A: N2 u! x' i& f2 I3 m% z7 }8 A
6 o2 P$ g0 _3 W2 x3 ~/ x
gen pmaxphddy240=`tempmaxphddy240' in 1, y# W. e0 L) B2 `( z
/ l7 A, k$ f( q
3 }: X8 S! o' G% J c *-------------ddy240pmaxp右侧低峰值 -------------------# K h6 ~ g7 b" h3 E( d
7 c2 K: G1 C A! Y8 v x
preserve 4 G3 E4 e# I! U
! i9 |: ?0 X# u* h2 d2 N. X keep if dx240>`tempmaxp'5 l: h2 h- o7 W; j
; K, G& R8 ~3 @9 r5 d: j% a' u! [
gen temddy240=-ddy240
5 S( s6 b5 y, D" c4 L
% B `7 }2 x2 o& g7 D8 F keep if temddy240>02 E8 Y% q2 H. P/ i# @. p
! i/ p* }' P5 R2 ? }0 L U7 v count! E$ w) o! h1 f$ q$ Z/ @" p
. H( l: P8 s! E4 H/ G q if r(N)>2 {
: @5 j7 R1 s1 `# _0 B- U * x4 \) _( V7 c9 p6 D# a
pkexamine dx240 temddy240
2 z. e, ]/ K- } / {5 K- k4 h1 ^7 U a
local tempmaxplddy240=r(tomc)
$ H0 U% N9 N1 P/ w3 {; B restore
# b- l+ f0 y" E$ u: r }
. h6 ~) ]& t2 ?9 d
2 t. T* K+ g; {- y9 m' ^ else {
: \8 E4 {" T/ _2 [' ] restore
) ^5 {7 p2 P# g! g di "cannot find pmaxlhddy240"- W& L: B) s& K9 e
( s _. h0 u# G& t / N+ h3 @2 K6 c4 p J2 e# O( n- v
sum dx2400 h3 R7 L: s" x, k) V+ I* g. u
local tempmaxplddy240=r(mean) in 1( l* W$ P1 A8 g% x
3 l% A! z4 n- j8 R2 m$ ?1 T- n
1 Q( d* j2 H5 |/ i- d8 l/ _ f
}$ `; q; N h; f' s) K
: m9 J1 N) w7 ^, K( T
9 I% x% A: ~/ g3 d# s8 v5 p
& W5 C2 \7 t7 @
% H0 X# W9 ~/ `* A
. O' o, M5 c3 i& q $ X% Z; C& _3 g1 n& ]
gen pmaxplddy240=`tempmaxphddy240' in 1. \% y7 z0 m5 K5 y
5 a% K; Y2 h: T& r/ k *-------------------------------------8 n% R$ o( T a+ a5 `( A6 K; v
' t1 K, l' r5 U% @& W# r! k9 _7 G& A
gen price5d=v5 in 1/20
/ f' e* E* ~& J7 W
, y( v- D. R$ n9 [. S gen price5yy=_n in 1/20
8 Y, {9 K# @. ~7 f7 V $ X9 n# h0 j E3 R* a3 ?
gen price5y=price5yy*(dy240max-dy240min)/20
. y4 E2 o" b! u' T & Y6 s: K$ p9 W$ o2 H% a6 C$ @2 K
*price5y &price5d- p* {3 z, e6 @4 i% O
" Z: A3 {: i/ a gen priceny=price5y in 1( M/ N) ?2 n# y9 q
) w$ _0 v$ h0 H2 N1 H/ L gen pricen=v5 in 1: a7 G+ A' \" ~$ i
c5 I, H" W$ K& O 0 g: x+ b7 ]' C' L
*priceny &pricen) @. K* {. M) S. z5 z* `
& `, [9 X& t5 f * S# D% u4 Y8 w( w
*-------------------------graph------------------
7 v$ }" q* V" _! p s 2 _% j O" J1 o8 B" ]6 D0 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)9 A/ y$ ?% K! x7 A
# y! ^4 f8 t: C# N, ?
* ---------可选项目----------------------+ x6 {9 U) V% ]3 [
*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean))
$ Z1 g! E; [: F}
: e: k( n- k K4 o$ b' _end
- b; W9 D$ {- X |
|