|
maodeng 发表于 2013-1-28 13:13 . D/ p( K( Y4 f; V9 h+ C" _% S
. hello 300236
4 O4 M3 l W0 t2 D( C: \statement out of context! }% \( F4 D7 u: ~2 G* F3 T
r(119); % I" [( p; _9 R
抱歉,最近太忙了
0 `0 L: E% e, N* N
- C2 y( E& O W2 | f300236 我用下面的程序试过,没问题
$ j' S! U' V% ?/ B7 b& |" P& ~: r4 s* _4 m
你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试
) k; ]) E; G' |' S0 ]2 I6 M: r. F( }" U9 T, r8 p* p
capture program drop hello
3 P. f; K) ^6 ^0 u4 [2 _/ q4 h7 g" F j: M
program hello2 N) ?& z" C: B6 D0 X- `( E2 L
9 ?" |' V' Y5 @" @
quietly {2 S, y; q! D1 n z
5 j$ t& J( E$ @# U$ N: v
clear4 ]/ c% l( ~7 @' \3 t( z6 b
) X' k, |/ O) xcd D:\stock\test\source% A" m# P$ Y }5 q% Z
6 v2 e+ Y) R1 Z& {5 q
insheet using `1'.txt$ y$ i& L( P2 C6 L+ U9 J
6 @) M) Y1 E: \ q; L
keep if v5>08 p4 e0 w9 I# @* e6 W4 t& y! x
+ `) F/ ?6 v( T c% n- _) I gen vt=_n
3 S' s1 B9 T/ N" G1 ?$ ~8 t* l7 Q 1 T: c R9 S- L" v
tsset vt. U/ T6 z. y t7 C+ e
( S' ~0 x% V: W. ]# u$ I4 Z+ p& H gen zf=D1.v5
0 P' |; ?- ~5 H9 V$ ^6 R+ j' [2 h2 r1 k
gsort -v1
" @; o" n& t) N( c0 a# b4 P+ q
i9 ]( z2 Q+ s. f gen avol=v7/v5
) e; K3 b( d% S$ D# D
3 [/ Z. |: e3 q4 S keep if avol>03 l# ` n- A0 Z, O) Y/ j0 U
7 x2 k/ Z( X- j. L/ f! [ drop vt
5 }; I3 T; ~6 G1 R & w: V' x1 E+ z* l' I
gen vt=_n6 J5 t* j9 M. W! Q
' G. ?3 L8 a; o. S" V- o) y3 r tsset vt( @* _, \* _- u' {
( E% Z% b) O! L9 D
sum v5 [aw =avol]
4 w. P( }. t+ A+ k' t7 o* `4 M" q4 E; n R8 Q( z. V
gen amean=r(mean) in 1
( i6 F/ l0 X% G5 U. R0 Q; a
% h8 P& b+ b3 K4 z8 Q/ D( `' g * 总加权平均值 amean+ l m$ g/ e. Q! @" {
# \, x/ q: |4 A: b & y4 C9 V2 f. O; U8 y
keep in 1/2401 {1 o( s% b" ]! {
0 i# i; {$ }4 h
sum v5 [aw =avol]9 ?: g9 ~+ V( Q) C" Q. S8 u7 y
& U0 g$ B# J, R; k R+ @- ^ gen mean240=r(mean) in 1
# c% z D9 N: I - {) H. r( S9 Y% }
*240加权平均值 mean2407 F4 \' Q0 d9 s* V4 L( G
& f- M9 J* C7 w2 u. `5 d1 U: H
set obs 500
+ h! e1 Q3 q3 ^" ?" `
7 K$ H" E2 j' _' q$ r2 j kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
S* F) `7 n) I0 k
* k1 {- G5 U1 D/ p% O" Q& Y *240 kdensity(dx240 dy240). m& A! |4 m/ K" O
( R. |, a- R# r4 `' i! @" s sum dy240+ X2 h- A9 A5 {: B8 B
8 H1 h2 F- q2 @; k& E gen yxis=r(max) in 17 j- g! C( \" ]7 m$ z3 k) b
$ s3 N8 Z$ x% ]5 U1 I5 R
gen yxis2=yxis/2
$ u6 m! t1 V* Z* V! b - W5 h( @* O) b7 O+ i/ O, B8 h6 T
*yxis
1 [4 a1 b j& P% y
& w5 d- N& e: U, M( \6 a& v gen dy240max=r(max)
2 Y3 w( [7 o+ ^' B0 J$ y3 m / J1 n1 S1 \( y. }) [8 P4 T) v1 [$ F% U
gen dy240minp=r(min)
/ l. ^9 U/ z, Z9 x/ j 7 e/ K) ^1 E5 B2 d5 T; `) |
gen vtt=_n
) N7 l' u' b z& X# [2 R3 p. |0 r7 |. v7 r3 G& B( ~, a3 f
tsset vtt
1 l* H& H4 l. N7 n
) Y* \7 s/ S! x% F gen ddy240=D1.dy240/D1.dx2406 _3 `% M& _) j$ E, `1 ^2 ?
$ d1 f3 m9 t5 e( F sum ddy240
/ ]0 L5 _- J0 P D4 o- J1 @ 8 L5 X/ z* ~4 F: X, p: @4 J
gen ddy240max=r(max)
& U" Z/ V6 a( ~" C& k, c ; n, [5 ]: E5 T6 C, I. v* G
gen ddy240min=r(min)
( z/ Y" P( G# k* U" u: P) f' U5 w
8 ?6 o6 Y: t' R$ r& T gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
, E9 _7 @ r- u $ w% v$ N+ E! K5 t+ t
sum ddy240g
r, I) n6 r% F' t5 l+ U 9 ?- B2 p1 d! J3 [1 x6 L3 W$ e
gen yxis3=r(min) in 1" U5 `7 K+ y b
) E5 U) ?; K% D+ K. z( Q7 c+ k gen yxis4=0 in 1. X O/ u! a' O5 P4 [6 T. [
) c4 r' i3 k% c' O0 A4 l *ddy240g ' u3 \* Z2 P8 y2 }0 U0 s9 L9 K2 R0 C
% N3 L1 J i, `
; `7 Z4 T2 m6 e
preserve % @7 v6 L( x" @$ X% v: E; N( e
' W o8 D4 S& p4 n sum v5 [aw =avol]$ w" S& D5 y1 i
# B( E, N3 B; H
keep if dx240<r(mean) ^9 k6 F& w% A8 R
3 a$ C) m2 B1 Z' c: a3 m sum ddy2403 N! N1 Q" d6 h$ H, ^
1 G4 o. k, ]7 _5 u/ q+ Q
if r(min)<0 {: C/ P# ?; C6 ~! S6 x( ` b8 `& _
& }; h( {6 T5 i
keep if ddy240<=0
; J) [+ R2 N& O % A7 O/ A/ }; b1 U0 D
count
7 M/ _! E& w% A, d7 O
4 S6 e3 N& }3 B. @% D+ b+ T | if r(N)>2 {
" e$ Y1 R% T: H1 ~$ L ?. M+ n # z6 f) F2 @! g. D+ m6 y
pkexamine dx240 dy2407 d! V+ d+ |+ W# {4 m! ^
2 N, Z2 v9 V# r local tempminp=r(tomc)
; v6 R' B6 V+ l6 Z restore $ O6 N; }; {1 f0 Y
}6 Z3 N4 g9 _% [
8 x; [+ `: q8 e: a3 t
else {5 x, j6 `* ~, ~$ j+ V( m0 U
5 q+ V# R/ E3 F0 {9 P2 y x di "cannot find minp"
4 \; v3 f( K$ `/ H ( t1 y% h) R; Y; N
restore
! i4 }8 ^' G' l4 W( l* {0 K/ |. E; J sum dx240# a5 }2 p6 p9 j* x
local tempminp=r(mean)& q, N5 k) A. ^/ H, g& |( M
; I l5 M9 p! ?9 K }% Y' k; B3 i9 g9 Y2 |) h
}- p# Z# s6 w- I4 m
else {+ \5 m/ F5 |0 p n6 [& O" y
6 O+ M& p( X% c3 r
keep if ddy240<=r(min)
7 ]- ~/ W7 j1 r' p1 F. ~ 7 b1 {. o/ A; m9 X1 h' Z
sum dx240
% U1 e. ^% D: d" H+ t, B; K1 L ; V1 K; W( b1 N0 j7 |4 S
local tempminp=r(min)
# R# D' c/ } m5 Q! C K$ J restore 9 a: T9 `# M) @4 O1 `, D& U
}! h& y9 k. B# v* q8 _
( J! S' F7 i. Z) f3 M/ P4 @' j4 @. D }3 c8 _" ~7 j
, N) f2 \8 J/ Q; o& A% g% Y
gen minp=`tempminp' in 10 W/ h0 ?# e0 D5 Y/ z% x- i) ~9 N4 c
*240 minp
- H# b% C7 i- i( h; O2 t3 j \4 U
z9 M! U- A) H6 {4 ]' `1 @8 f8 P4 @6 K* Z* @" ^# \# Y) R
4 W# h( e! O F) O
preserve - @6 t+ r1 P) h- u
3 l3 w- F: u1 u
sum v5 [aw =avol]
% d6 ~9 v) E, x5 ^ ( O6 C- A; U. g7 P. I
keep if dx240>r(mean)9 ^# a8 F9 p4 X7 i7 g: ]( e" \
! ~; O6 D8 k; ~6 ^" j sum ddy240
/ z* q5 R' @( S! J. M% c7 Q . z& S, I3 w6 B7 F" s) m7 V0 H; r
if r(max)>0 {7 K; z( I/ f6 X! x# |5 q
' M- e2 g* }: }4 t7 E2 `1 \
keep if ddy240>=0+ J' `& E. ?' [4 b0 L* }
" u8 N# D- g. ]8 q5 [5 `/ L# m count) n8 ^2 i6 U6 A, G
$ P2 p8 A0 d# W0 m7 C1 I if r(N)>2 {
. R: n9 G. b- s w) P" T8 c* ?% }
pkexamine dx240 dy240
$ Y2 E3 S6 T( ^; {5 @4 E& ]9 D+ ^7 a- \ % u; Y# d: E+ u& l
local tempmaxp=r(tomc) 5 S4 W& S; X A$ n8 Q- T
restore
+ x9 J% w3 c- j; z6 m( ` }
3 ]) c. M& @0 n( R 7 O) C! \ ^! A5 q
$ R7 o f" i3 f else {. {8 c% t0 \+ |) G* P$ ?, F
restore
: d% Z s: M* i' j di "cannot find maxp"4 A# p* V/ A7 w8 p4 e
0 _, Z) y/ g# L9 l) M$ A! }. W
; R3 |- n5 r" m4 p0 p" ~! z+ W sum dx240
# t4 ^% o& @( B, }' \7 N local tempmaxp=r(mean)9 G( w; ?" B! x# j, [) B
( x6 B. O# z4 J" K: a7 {
}
0 [, ^7 u! C% d: V0 k# V: N 2 g& Y! c1 j3 o; K* { _
}& |5 i7 Z. }3 S! f: t4 j* z& r0 Q: w
9 k) {; R' T3 l$ r1 J else {/ j. H, U x' U3 J
7 J( `0 k( \3 \, ]; X$ Q8 s keep if ddy240>=r(max)1 M' }/ S' B1 a
/ S ?4 R2 n! c: H/ q. P7 J. P sum dx2406 e& d" R/ o+ F" }
8 R" v# `2 V" x, F$ G- I local tempmaxp=r(max)
: K5 e3 w/ l) Y9 b5 {! E restore : p: J% h" d1 V: M% P+ V/ G T# N3 J' @$ X
}
5 k3 @ K) n5 a n" V % X9 w5 K. f/ ~- l
a/ @5 X0 s: A( I/ ?9 U
3 n& B% \( m4 b; N1 d9 r0 R4 S3 B, B# H! N* R) H1 U
gen maxp=`tempmaxp' in 1- k* O) g& L! u& ~6 h, m! X
$ E, }8 {( C5 e) C *240maxp0 C$ j( I4 W) H( t3 G
' {+ m$ g5 O$ ^4 b* H6 L# L$ B ; o" Y; S/ q7 P1 Z6 C
*-------------ddy240pminp左侧高峰值-----! x- y* l. l3 @. X
6 f4 e$ @. J3 h2 f6 g preserve 4 I0 e+ y. [: M& y
( a( U3 H1 {6 C& Q. E2 G2 T
keep if dx240<`tempminp'
/ g1 F6 ?) y* O2 [' S
" U1 L; |$ C+ V" h0 [# L6 [ keep if ddy240>0! [6 [( Z% }/ j
7 B& i- w6 G4 E5 f- |0 O
count6 B' G; B+ E7 _8 T
1 l5 z' k0 q. o6 I- p3 I if r(N)>2 {
2 @( l) w- E5 q+ W X1 _% n+ Y
/ q* d: R7 P1 L4 ~$ ^4 A6 [: t pkexamine dx240 ddy240
" ^6 U: F+ E3 X2 J: @/ w) x5 @ # n8 n9 ^ A! Q
local tempminphddy240=r(tomc) ) P& q" E/ n: L; Q3 _5 f1 p
restore
- R m3 b7 F$ @0 x5 [6 O5 j }
3 M2 n$ ]! ?" K$ ]
% ^7 L: g5 h+ y' W. O else {
, v0 @; Y; O+ P. T/ O restore
/ M# Y [( `" V0 h di "cannot find pminphddy240", D; v9 C- e- a8 {$ L: ^+ K9 V0 g
1 y K! D3 c* o
. h5 y. q6 l5 g; k H
sum dx240- J" m. c; t- Q5 l3 n
local tempminphddy240=r(mean) " o4 s1 U) N; Z6 M, [: i
: w! j' _( G# \! \) Z* E
- u0 D7 {7 Z! ?+ K* ^1 ^ }+ M6 I8 C' i" M( V% I3 j( q
; J1 u1 k4 J9 c4 C0 \9 ~# }6 n
2 M6 b2 j g% {$ Z4 H: O
5 x" w( S( a; L, x3 R% b: l
7 m0 e* S* K7 G; }/ O 8 y8 D2 l8 ]4 Q% i8 I9 G& d. Y
; }' o- @- e* {, ^ gen pminphddy240=`tempminphddy240' in 1
! ?% F1 p8 `; _ % r5 m& q6 g0 H: C' c; `; Q" V
' b# q( b d. }& k+ }0 l, B *-------------ddy240pminp右侧低峰值 -----------------
- Y* N" R) V" I4 e preserve
( u" J' T; u/ ^$ d& U1 G9 B2 j% d' a
0 z- M( m, `+ v; |8 F. O keep if dx240>`tempminp'4 ]- k' n2 e1 s: S0 n
4 m% B; V8 j4 V: f+ Y
keep if dx240<`tempmaxp'& r7 h: } h8 O1 ^4 W+ E& y" T
$ p+ ?$ G1 |! `6 i& v keep if ddy240<0 s* @9 ~/ @6 p' o: l
4 S& _5 A5 e# {9 G4 f! T
gen temddy240=-ddy240
% \' d' ~4 I. A. l( I$ X
7 |+ K! p. j2 ?+ @, \: P0 p( m0 X7 L count
- b+ @# p0 D5 U2 r
/ q9 g) k1 [& ] if r(N)>2 {( Q$ n& m( f1 i/ W
% f) v" U0 |* s, o3 w3 ? pkexamine dx240 temddy240+ |. } e, _/ M8 A0 Z# R! C
- ^# n, q% Q3 f' J; S local tempminplddy240=r(tomc)
4 F$ f5 _7 r2 S3 x restore, u' E9 w4 y9 J
}: e; b6 T5 L9 I* c7 P- X0 z
( ?& W! Y/ h0 A4 d6 ]$ R# f
else {3 k" i; L6 K2 X7 g) c2 Q1 C
+ L/ j' m- e. ?- d6 C: B
di "cannot find pminplddy240"4 G8 v! b/ L+ z% F* M1 N) E
restore$ m% p7 R2 F; D+ ?8 y
. [0 x* X# R7 k# @; t; q; a2 m( s$ X
sum dx240
* C% Z; A, \0 P& ~% @- g local tempminplddy240=r(mean)
# M! A/ @6 s( i Z9 S& V3 e
. C2 h' J: X/ \2 H$ O; `- q" z
! i( H: H0 U v* P }
( w0 j. Z/ E) q8 o7 q+ d" }. _ 8 Y/ j t3 z9 ]" C) K: Z9 Q
5 }) M+ ^4 A1 K* C1 w: c3 C2 p
' v- o. |7 {$ U9 @ Z9 D o1 a' l
d1 f( }4 b9 z ( Y9 a; Z, `1 d+ J3 j
gen pminplddy240=`tempminplddy240' in 1
, W+ s" G: E. e8 [ W1 f' p 7 y& ?3 |6 L, i+ ^ T( t) F& {5 ^
*-------------ddy240pmaxp左侧高峰值 -------------------
# h% ^+ \0 T& s# e* K1 [ 8 f- x; Z8 @6 t' @
preserve 9 B7 `1 p' N5 `8 g4 [1 _% g! f
" u/ c) S$ T. a5 h ~2 t/ \! G: w& `
keep if dx240>`tempminp': n) x- X$ y+ |9 f; ]
- |- J! E) t4 Q) G2 F1 ? keep if dx240<`tempmaxp'
# ?: K S/ e% e4 H
9 s1 q3 Z }1 @ keep if ddy240>0
1 `) q3 ]3 r( `( a& G5 R count2 ^0 F7 P+ V3 j' Z7 W3 ]/ O! S
3 J* X' ^7 T- {" Q: F3 j& J if r(N)>2 {
2 U4 ]+ N; T& C
2 i$ b# c; y( d! W, l5 o pkexamine dx240 ddy240
. m1 R( i$ |4 H( \ S . { i( ]2 ^. X
local tempmaxphddy240=r(tomc) 6 E0 V+ b. [" O4 a6 G9 C
9 X7 Q" R* ~) q; ^1 [ restore
8 D. U$ X5 \ I3 E" H# p }
- x9 u+ V- N, w; y3 b8 U. z
6 U9 l! T7 p6 O0 q6 a0 t% t5 n# W else {+ V7 | A" ~4 C8 ?- w$ b7 v
' S1 Y/ w9 L, |) [6 A' t3 w
di "cannot find pmaxphddy240"" X* Y( t# b- s) P2 g) u
restore
# t+ |4 w; ~3 m2 b# v- Q" i
- _! N( F x; x( J E* o sum dx2407 G, O2 X: x) W9 [, E
local tempmaxphddy240=r(mean)
5 @4 w6 a3 z C3 L
b2 U3 ?% V. B* k
7 @& f% ^8 \% |# J5 b }0 U( v+ @1 t. E J: I/ N' ?/ G2 }2 _
" I3 T4 f/ g ^" @* p
; `7 _8 U3 i5 t! _- A) F: t
J, A6 z4 E: A# ]2 o # v( o+ {3 y8 l9 S9 f9 R
6 I. ~# h: U0 i1 t' H ( i B; n* |/ i- O/ Y% j
gen pmaxphddy240=`tempmaxphddy240' in 1 r. Y) z( m! U2 Z* T/ ~
$ z8 z2 p4 M" R# C+ @) g" I
+ }/ {; u4 o$ P& \; N0 k' Z
*-------------ddy240pmaxp右侧低峰值 -------------------! D, k, }+ E( N
: [9 S, l6 B1 T, ]* s) d* q& s
preserve
$ g8 M& b$ w- e2 V
& l/ l) y! T6 S5 a2 p9 g keep if dx240>`tempmaxp'% r1 ]2 E# O# {+ k) r. Y2 {
9 K0 X" N" E/ v% L
gen temddy240=-ddy240
5 [ t! L6 k+ W& N3 g
! f" K$ ~9 G7 b% Y/ G keep if temddy240>0
, ?) Z3 A& ^2 t V 8 H- Z- W3 d$ ?$ X2 k
count6 q5 X5 Z$ @- Z2 E
; f2 d4 Q# |$ @5 t if r(N)>2 {
1 j% a8 _( B' K- M& |" F # h5 v( k- L, @+ x9 A
pkexamine dx240 temddy240
6 V, m- Q* _8 e2 R" W; @
2 J( o$ _, C: |4 Z% m9 m local tempmaxplddy240=r(tomc)
, R" {9 `' P5 c6 A restore
, P1 [: w3 M2 O" l/ K9 Q( g }: t# t' J5 Y, F5 ?
( Q+ L# x4 J+ g3 R1 x
else {/ ]1 B5 Y7 M& T
restore1 H0 k% }3 r3 M
di "cannot find pmaxlhddy240"
R) K: H9 }" d' V1 C 4 J' H1 o; ?1 ?: o; R" n7 r
: U% S+ r* X7 J& l1 V
sum dx240
- P8 t8 L' P; y3 a8 i8 D local tempmaxplddy240=r(mean) in 19 b+ |' w7 q$ m/ N1 M& c
2 s) h, H6 z, | W
5 g/ ?2 W: W1 D( p5 A
}
/ s) x c. A1 O9 \: M - h1 Z; C. S4 C- J% w6 a6 J$ H
6 L: E& `2 u2 R* Q5 l
; \. m& A/ O D 7 K9 o3 {+ e5 t2 `) z* W4 A7 n
7 r, e, A! O, R# y; v
3 A2 j# Z9 K2 s4 t! o- v; j+ q gen pmaxplddy240=`tempmaxphddy240' in 1
6 H/ A$ v- i) t/ m 0 }4 _' D9 M/ q* ~4 R. p' n, _1 t
*-------------------------------------5 w# P6 W) j( S8 @0 K( I: u
$ s# i% K) W( n( Y; k gen price5d=v5 in 1/20
, M. Z8 k$ b' A2 B# t6 D+ | 4 L+ @% V4 c9 M; s
gen price5yy=_n in 1/20
: d# ? j* r7 }
- S, }! Q |" S. Z' J6 _* P7 l9 d gen price5y=price5yy*(dy240max-dy240min)/20) G C0 N+ Q( X! J
" q' K& l# ^8 l: C1 g$ W *price5y &price5d
6 c% W+ @! f$ Z3 |3 b $ W7 V* o% p: a) M2 \" Q
gen priceny=price5y in 1 w( ~( k" L7 d4 c
, Q0 t$ i6 j% a F7 p gen pricen=v5 in 1
7 b) Q$ @. B6 X' x% r; [4 u3 V- {4 _3 O& X* `
4 S0 M9 W* n( ?, a& Z- n4 @
*priceny &pricen9 \: X4 C0 g: s6 z/ z
; N3 l& n2 K N/ G / l1 q+ j* i' }
*-------------------------graph------------------
1 q/ m8 `# e- I. \$ h) x9 W/ t ' T6 e* R* g% P* 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)
$ n% ~2 |" H9 t9 Z1 Z# x" |" O" P+ y4 Y5 u8 n3 j A1 p
* ---------可选项目----------------------
4 \4 e# v# z# H, |) I4 _*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean))9 F9 e! n& i. v5 q$ f$ u* w
}
2 \( f0 |, W# f m' Zend. {1 h+ @) {+ p+ a1 i
|
|