|
maodeng 发表于 2013-1-28 13:13 , L- t# C! _# S* V7 K& B
. hello 300236
5 k# `" o |8 V) m/ W nstatement out of context2 S0 ]+ \: O5 x$ |5 N" P
r(119); & w' z$ y# j+ o) E$ R# \* R: ]8 v
抱歉,最近太忙了
/ I) ?9 ]# H6 y' @" V* x' D7 k: Q: Y! z0 [
300236 我用下面的程序试过,没问题
# ?6 t7 W9 q5 o% D" ?' { J, s, c8 n4 N- x
你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试5 w9 n+ \2 d( I" t
: B: b, ^: {' O7 e: D. a0 Gcapture program drop hello
+ n# N0 I- l& b! ~8 Q
6 c6 T' b3 @! m9 ~* wprogram hello" K% u- {. J8 P1 G( w2 a# {" I% |
5 u Y, `8 ^2 V$ x" _: s% J quietly {: h! ]- N4 f# s1 c- Q1 L/ d
$ ]1 i: k8 `8 r. Kclear L% O- R3 I7 a8 U' M, H7 q% Q* \8 v' o7 t
1 ]& s! h, h& a$ e: q: o; acd D:\stock\test\source
, H7 \6 k' L3 P9 |$ h' ?7 i/ R7 O( g" Z1 w* I
insheet using `1'.txt! C9 [( R9 y6 i
6 G3 A+ L5 h) O9 a" q
keep if v5>0
# k2 Y0 V6 l: q7 i
6 m R" O7 s) j9 O. Z( P gen vt=_n" I, i7 Q* N3 ?0 {1 Y0 I3 M2 ~% @
+ h7 C, F6 c7 D% M1 D
tsset vt
: H! w9 W' Q1 Z, c
5 m5 z" s! ~' O gen zf=D1.v5$ F2 H9 X$ d" F! R( Z$ M5 p
9 z: B A% D9 Y% l gsort -v12 S9 ~/ b: s, r4 q4 k+ ]" @; W
9 F/ ]! `" Q5 G0 ?2 Z9 M' ^( T
gen avol=v7/v5/ I9 U/ f5 `8 c$ }7 ?
% u! H4 T1 C, @
keep if avol>08 U2 ^! e) z2 T. c1 e6 A
# g8 E$ A1 V! F- m
drop vt
4 P. j( q, @9 H) P 7 _& B+ p: m: M- u) Y1 R# b
gen vt=_n& V6 _$ L" m, R; H
) n0 `' Y" `+ B% R3 H/ a* c1 d2 S% V
tsset vt _( l& }& }3 \/ l
2 @1 Z+ K1 ^* B- D" ^2 P sum v5 [aw =avol]7 \" c" r. X2 W) W7 `
) \, `) e* B1 `7 f( Q7 U6 P1 Z gen amean=r(mean) in 1
3 ~8 F6 ?: ?& ?/ @ " C; O" T: V4 V) ?4 d0 T# Z" e
* 总加权平均值 amean
/ k& I$ T7 {9 D3 ]% J
' _7 O* `# S0 R 7 c1 S$ S5 x' Y$ D
keep in 1/240! Q6 }! [; u- V
. T. b8 n9 M% A# J sum v5 [aw =avol]
! x3 e1 I! v1 a$ T( r( L
C' I) e1 N! \8 X3 v3 z gen mean240=r(mean) in 1 |* ^ w: k2 @: E1 t- P: u4 D
) G0 z, x( H8 L6 m* M) U$ ?
*240加权平均值 mean240& r3 Q/ v- o2 }# I
% r( H) k3 {$ S set obs 500
' Q/ x7 j/ p3 D) e3 g- s* p
9 ?# x F- {1 y! B3 O9 ^. b kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
3 I/ ~1 U! l9 q! E2 V 5 A2 z& ]5 D/ F% z* j0 u
*240 kdensity(dx240 dy240)# {4 L6 q7 h2 v: C1 Q1 }
! d- {% l# q( S1 |3 [
sum dy240
) G0 Z5 r5 ^+ o: @! z
3 [* o' K# A! B2 l# h gen yxis=r(max) in 10 h* I1 b5 ?( K& H" N+ E
# H1 g2 \/ @* g( z, r9 A% m
gen yxis2=yxis/2
' L( [6 d+ Z$ T0 t2 o- G$ x" P ) U/ R3 Q4 w ]$ a- z
*yxis8 E+ S. @. m6 `# B1 K3 E
: ^ I2 G: p; S' b: K. ]/ |# K gen dy240max=r(max)! F8 d* B8 _& L' Z) u% Z
. v0 _3 {' f$ q' V- @ gen dy240minp=r(min)
- q& V A8 \1 o " W; ?* c4 Q+ y9 ~4 g Z, `
gen vtt=_n$ y Z7 d4 I" U$ k2 Z
' Q# d8 u. F; ]% [ c4 W4 y, R
tsset vtt
1 k( j+ F% b( q$ O* B2 |3 ?: C4 ]0 z- o7 ?0 M. v
gen ddy240=D1.dy240/D1.dx2401 V! E" M6 k2 M) Y9 j6 t
$ ?8 m7 {) b1 Y# k6 v) H) s
sum ddy2401 q. M8 S% X4 E, B# o0 t! ], y
& \% E. k. d: `$ z
gen ddy240max=r(max)
2 L4 ^0 ~1 N6 Y3 A * T" S2 T( ^1 d4 @
gen ddy240min=r(min)
f4 U+ M5 C% ~0 v" z 0 o8 N9 {# Q; R* t
gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)' a$ F7 h% h7 B) x8 K* A
+ q6 p, T1 l+ n, @3 }
sum ddy240g/ w* ]; L( e! x5 B# B
9 `& P7 A2 t& \4 {& A9 {- W gen yxis3=r(min) in 1
' ~& i& Z$ b5 Z9 o7 Q
& L7 v& E, n2 u: X: i9 q gen yxis4=0 in 1
- F3 l5 t- E6 V( s0 z L5 @
( c/ b. C- B- y7 H9 b: _% h *ddy240g
2 ^2 R, c4 I3 ~+ B+ b0 k / J: o5 h9 z. k y6 B
7 @+ e j& M8 h* u preserve 7 M0 E" w$ j1 M! E/ u5 ] p
) C# f4 P9 P& K sum v5 [aw =avol]# q# p q1 x% h. O
; i _/ Q: z5 I* `: ?
keep if dx240<r(mean) [; F; X. K/ M4 q8 [' p. X
) O3 P3 s, G& }9 \3 D4 ^) a sum ddy240
8 \7 O4 l* P" f. R
$ s; z8 F- E" U( H9 c if r(min)<0 {6 u. _: |! k7 \
4 c H) I- e- j% S6 E
keep if ddy240<=0
+ z1 \) h4 ^3 a+ b. ~6 g
' S5 j" [' d8 z5 H: Z count3 t! S3 A6 N* ^$ J& x U4 A
& V' h3 V( h& F if r(N)>2 {) a' |$ }+ o. z+ \ e' I
: U+ F! I+ E# M9 ]" m9 n pkexamine dx240 dy240) P; [. R. k, f# N' x
/ W( f3 E7 [$ T+ J- ]6 i local tempminp=r(tomc)
( j2 W7 L8 u* o; p, | restore
( v1 ^; `4 C* p X/ q" A1 j }
. |3 Q/ I. [" V; p$ H, O
. _& Y1 l, `' z0 L4 W else {9 H6 x9 d& ?' N1 F2 L! e7 p% `
1 a0 L, S5 d2 T- \
di "cannot find minp"& j; p6 s Q9 L4 D4 \
5 P& h/ R' C0 U2 ]& V( o5 g& {3 z4 \
restore
6 i( w0 m1 z; N/ n9 E sum dx240
, Q) U% b. h# j& K9 u local tempminp=r(mean)/ B. V: M/ i& z( x
) O! l7 P5 f5 q; t5 ~3 i1 Y' o }2 m1 e+ a: \! q
}2 B2 W& t; f4 h, r: N1 L
else {' A2 u3 h7 j! H/ U9 Q% p8 [
& L f% J8 w! s! |4 `: W8 p$ H
keep if ddy240<=r(min)
: J6 V7 m( Z/ u7 M6 `0 w' |6 ] ' C3 u; J7 P+ ~3 U7 H7 P) U$ i7 V4 W" o8 ?
sum dx2402 J( i7 D6 B* t7 y7 ~1 p7 f1 C
% l3 _: l( _8 s) b, }( b; Y
local tempminp=r(min)
: V1 V1 |0 t' e t$ b# E& O restore . Q1 @8 M4 z% x; x+ W. o, |
}, ]. i9 @9 t! W
3 `4 ~1 U( m/ v6 C# e/ T$ T4 z" D
; |+ D x8 i. r1 o$ C! `
D; O8 h% \" @. S4 D+ G Y
gen minp=`tempminp' in 1% p; V" \7 \, H6 W; e
*240 minp% g8 u+ Z: o5 h2 Q7 a4 F
1 l: f% s$ x! R
* G4 E6 L+ P$ W. B0 K, v 4 G* Y) {! O( s9 y: {
preserve $ W; S2 p `* e$ e: {
* y) Z U5 V/ e$ `$ D( p+ F sum v5 [aw =avol]
- L/ p- T' o) D l' M+ Z 1 Z, [; T: h9 a2 w
keep if dx240>r(mean)
. x. g4 } r1 | 1 W/ L) R$ n; P0 Y/ j f) ]
sum ddy240
* [8 s2 e# B3 n- T8 U) e
0 w2 _! J/ }; P" Z9 `0 | if r(max)>0 {
+ [7 T4 k4 s8 d, X
7 n7 w2 O5 R2 l keep if ddy240>=0( T' X0 u: W" o" m+ J# S
6 o* U7 J$ J4 F0 b2 Y
count$ k5 J' b, D$ \; @0 ~4 [
$ k, l$ `: z2 a9 d" B' ]$ K
if r(N)>2 {
/ v! C" b# x4 U9 ? % E5 M2 f( g/ W- W3 ~# c$ f, U- ?
pkexamine dx240 dy240
+ {! D4 w; R6 i- D% T: L4 w- t) ^ 2 u7 Y5 e5 F! A( z7 U
local tempmaxp=r(tomc) 9 n/ \0 j/ {" i4 ^+ q5 s* H* ~
restore # ?/ s( O* t% ]; ]% w" `
}
* H8 B% c/ ]& n# }) s
8 a4 i9 y8 [) H: @9 G: y4 P8 i " C( j+ y( ]! k1 m @1 K# c" N
else {
+ ^# ?* p( c* L restore
6 D2 ]8 o1 w( J$ j di "cannot find maxp"
9 s* i; w/ w- y8 `
/ t. ?6 Q& H- r* u4 m- J) G& J5 [
, S: n' t+ s6 N7 P& {$ p1 w; j sum dx2408 R7 q1 o/ }$ g- H0 l
local tempmaxp=r(mean)2 m' j* [6 N6 u! M" ]' p$ E; b1 {
- |) f# A- w9 g
}
2 s; y, k3 t/ y a9 ^ * a& \( ~6 [+ B
}, d. }9 m6 R7 T6 m% W& U3 ?
- d/ z" O/ M4 D( Y% D* t, _7 D
else {+ i. G% U4 _6 N+ U
) I# A" M! B) e0 y- S' R
keep if ddy240>=r(max)- K# v9 x b. h# F3 `. x) e
( T( S* m; p( z* U {3 ]$ z9 [5 A sum dx240
& i; f: Q+ |+ \8 w. j% h
3 C3 Q0 r! {# C; h3 b- r local tempmaxp=r(max) / c0 i2 |: ~7 H; T
restore
5 A+ H) {0 ^3 i. M }: ^/ @4 K. A. T$ N
, A+ G% q( I( w, b
' Q- z' A v" F$ c+ j
/ P: R* j0 E! y2 [2 b
* P1 K6 `5 b* L& e gen maxp=`tempmaxp' in 1
; }9 |0 E: q2 |6 |9 f! z 4 a+ ^- d" i: V
*240maxp
* M" @0 W# l! y ' u( @- p7 N( O. T8 ~3 W4 G
% H: `. d. j" U/ Q *-------------ddy240pminp左侧高峰值-----8 I. h% m7 ]4 \! P
- o6 n# [6 Z7 | preserve
# g% {) O q& t/ _
) w1 K3 w" z5 S: c keep if dx240<`tempminp' e2 o8 t0 t# @* @0 R( j1 g; C
: Q: T9 @" m$ C; \/ [( S3 g# a keep if ddy240>0
3 u2 S( P4 r. P) M2 w
3 | Q+ S1 Q2 O% L7 Z% \ count
1 v. e' l" O( v& U5 f/ } : h# Z& O0 |0 W7 M! |
if r(N)>2 {
8 j6 c% v( J/ ~7 [# Z4 m+ m+ U1 S
' F: `8 T+ Y3 e; @ |7 f* ]: K pkexamine dx240 ddy240
6 L& a5 G* \$ I* c) L
( \+ ~4 W! u1 p) i# {3 R local tempminphddy240=r(tomc)
9 k/ c4 \0 [, ^( n0 p restore0 Q [; Q, a2 f1 n0 ?
}
5 x( Q, u/ Y7 y3 x( ?. f 7 S" ]% K9 @+ ?, d! g- E7 j
else {
8 v; e. \. V( U- y' b8 ?3 u$ |9 G restore
H7 o& U# ]$ E3 x di "cannot find pminphddy240" B* V$ w P: D+ a7 U2 u
3 z: R) m7 S" A6 l$ `2 H6 l ( J* o3 N: B3 |( H3 k, D, h) r
sum dx240% ?% p& T: J- D0 R
local tempminphddy240=r(mean)
$ w- Z! B; q F3 E u$ H ) H4 [; B) E9 a8 R6 ]" Q( J# w
8 P* R5 e# T4 W, k, k) w5 q
}# L. u, L+ L! c% H+ P' L
+ I; N. \) R7 ]
H9 Y7 A2 ^& p; Z- F
# Y# F7 z4 \8 D- b ' c: m* K, Z9 q+ X/ ?
" M9 k- ]0 n- P) {! s3 T1 J( z6 A
4 p6 `/ ?( R6 @) K! Z8 z3 _* O gen pminphddy240=`tempminphddy240' in 13 K! `+ h) Z# |- W' m
8 e$ V% y6 f% Q) w* \4 ` # T" W8 \( X U
*-------------ddy240pminp右侧低峰值 -----------------" B& r0 ^% A. ~) f5 l) O% C
preserve
* J' W* U& b7 q" G8 M) j0 e
' ^! x: {: F0 n) o% `8 F) F keep if dx240>`tempminp'. }* ~; J* z+ f. F% p
$ Y& E! P- s7 B3 F3 y& p9 H keep if dx240<`tempmaxp'
% f, Q1 T) _7 }6 s
0 M. C1 H- C" M# j keep if ddy240<0
! s& m& W* g W, Q* } : }% V+ e' E% J# a$ J
gen temddy240=-ddy240- a' U( u. Z; l8 k3 ^. ^
) C% P2 O2 M: |1 _
count2 i5 p8 r5 h$ T
( V7 N& y0 q3 W+ E if r(N)>2 {
3 F/ _0 i) U0 f% |! m* E' C/ u
& a6 _" G8 [% C pkexamine dx240 temddy240! i ?" Q+ Q% P2 a
. k# M2 I7 ^: q5 S local tempminplddy240=r(tomc); A' Y0 ^9 K* e* G
restore
* A7 m, ?" P! S' _8 N }% O' T2 {8 N' W
3 L& a1 R% {3 b7 d O
else {4 M X7 j3 A* f! L% G: M7 V, b6 ]' |
$ D" }0 I7 `& ~3 I di "cannot find pminplddy240"; X. k, y( O. F
restore
5 v8 f/ \# a* Q8 C* j( b. O 4 z& }* }: n( P( t
sum dx240
+ Z' d+ Z" E" }( [* [ local tempminplddy240=r(mean)
1 u- H" o% U. Z6 {0 H0 U3 W6 \ ' Y" |# ?0 A2 O- j
; Q- n7 z- W& }7 f0 U5 { }% ^3 \( J* \5 u# m* R
9 H/ v6 H9 ~' i
x- z" w m% d( n5 R
9 T0 u- F- [$ c' C
( V- |) M& P9 G- o1 z& f
- U: R" Q2 D1 O9 J+ e gen pminplddy240=`tempminplddy240' in 13 ^# J$ U# ? k( G( Y) B
; z0 m- s( G5 d5 L' l/ G *-------------ddy240pmaxp左侧高峰值 -------------------
+ C9 P l8 P7 m4 W% L+ \. z% k( |
) g; j) E2 w2 T! P! B* ^% G preserve ) C5 c% z8 D1 ?; w/ [
0 L4 W3 R4 e7 I+ Z! ?4 G/ h) @' g
keep if dx240>`tempminp'
" | D4 Y, L* C5 `2 C 4 G* F. Q+ f4 Y% Q
keep if dx240<`tempmaxp'0 I. ^9 g/ N1 R3 x2 K
. e( r+ q W* c# }6 c- U
keep if ddy240>0
+ Z5 p! r; @( _( f; p9 ]9 v/ o count5 F7 {5 _( W: v: @! q
/ ^% k' {( R5 U* H# R7 l+ l
if r(N)>2 {
' N: d, x, S. p+ q7 V
) g4 Y& d1 `) P4 G, K pkexamine dx240 ddy240( | q2 W+ k8 \: W$ ~$ X
- G8 V2 m% ~. S" i local tempmaxphddy240=r(tomc)
$ \+ M& _' p% Z , M0 ^8 l! e( O0 C- Z) |1 c; C
restore8 ?$ e7 s2 ~! W! a- S
}9 S& i5 X8 G: l+ [6 y2 W6 n
! N6 ^" w8 R$ W0 P
else {
) p- K, h& Q* E+ @; f
% V' K2 v' U! [2 U7 C) J di "cannot find pmaxphddy240"
* t. b& R" L* v restore( M5 i3 E4 W) T8 w* h: y
; e4 X1 s# Z- Y1 E6 l. ~
sum dx240
9 _8 F: @ G5 _ local tempmaxphddy240=r(mean) ( l3 B& g& g+ p8 ?( y! W+ T5 b
; I* J( r0 j9 O- r / T' Y% ?9 E V1 a8 h* b3 |
}! X& O$ [: y4 q* E7 ~, e3 p, j
9 O. m& R3 N7 ?0 O, U
i' N% G* f' L4 O- L! g% R/ |
0 E; ^- V& z8 G1 A% {
2 [; I; `7 s" O6 [" O. P
) i- A8 [5 f# ~$ ~/ P$ M1 U
" }* q2 ~* S& G2 Z" n; U gen pmaxphddy240=`tempmaxphddy240' in 1) {* G0 w5 M" h4 Z" G y
e: y$ F: O9 J) `/ c
! Y/ _6 S3 T0 h: M% i: Q7 [ k
*-------------ddy240pmaxp右侧低峰值 -------------------
/ Q6 ^7 O* E& s& t0 T, C2 r/ }# m ) C* P; V( c$ s) L4 D6 B- ~
preserve
. J, O0 U, d$ _: J; b. O2 G
) a2 B* t2 D4 i+ X0 A keep if dx240>`tempmaxp'6 Q. K+ `3 K. E$ x2 q
% P q. Z. y3 ]* ^% z$ ^ gen temddy240=-ddy2402 f0 C* _, k% r% \* A; R
_8 Q- a/ C& Q7 P; ` keep if temddy240>0# I+ h% }8 @7 f7 U2 p5 c) E
) q6 K" S, r* K8 X2 U' h count
" h5 D y& q8 T4 }* t/ [ 2 f/ t+ T8 @! }% a5 w# l1 p0 z
if r(N)>2 {' U0 H7 v7 h1 z7 e! W) c8 C
5 o4 v% U. q8 ~5 D9 O pkexamine dx240 temddy2402 q' M- h( i" n. ^5 Y$ I( l
9 e3 h$ J5 P3 S local tempmaxplddy240=r(tomc)
7 d, ~) K7 b$ _. r0 |3 D restore
* N6 c+ m% F# m+ p }1 Q: Q2 Z; l8 W) k% C
- u" Y1 s- @% W+ u2 L( ?
else {
3 j8 Z, a5 x$ t9 g restore
% T- s* M7 V: [9 a. X di "cannot find pmaxlhddy240"
8 d: O0 l1 v* z. h2 ]0 [ X$ g- U
1 V9 ~ {, N, {3 Q! A6 W
( w9 i& h7 G9 W6 M4 B0 G sum dx240" F% G, O, G. W, b5 L. u i
local tempmaxplddy240=r(mean) in 1
/ g+ p2 u @ S/ { Z. Y" H 2 ~" c4 Y @ g" A' k: Q
( ?0 T3 c' O0 {2 Z9 z$ ~ }5 M9 }7 x' k$ A; P3 L* C2 \% b
- |! ?1 S2 I+ M9 p
% |, Y( s9 r9 C5 h# q 0 V& @' j; [+ a- Z1 {3 q' \4 \: y
$ }% x3 Z. a. H. |( X
% n6 p$ r, `% p% F
( u% E2 l6 `( ^ C( H3 i gen pmaxplddy240=`tempmaxphddy240' in 1
0 }/ u* o2 T/ n' z# p( d8 d# \$ E ' ~; e2 A6 v3 L6 n) s: C
*-------------------------------------
1 j% M/ F5 _+ F: c $ \6 ? L/ u2 T" N I9 f* `% p
gen price5d=v5 in 1/20
8 Q% [) Y) _. {. [: S% c7 }/ A* y
' [/ c5 w7 E! H' ^/ W gen price5yy=_n in 1/206 `/ \4 `" r6 I2 y$ H: Z8 x$ T* z, J
6 E+ v7 g# X) b% p
gen price5y=price5yy*(dy240max-dy240min)/20
% w& N5 t" _9 f. f Q$ B6 r5 w5 H" m
* i) A- y: z2 F: u *price5y &price5d0 I3 i( u* Y0 P/ S
/ ]8 w! V4 O) Y. B6 e gen priceny=price5y in 1
% E2 I4 l- a+ E$ [& K% b$ |2 S / I% V0 M& H3 V' C
gen pricen=v5 in 1
0 X( L- _; L$ Y) Z) o& U0 ~. {
1 R% m1 v2 X' [& `: I! Y$ ^6 Y
% y9 {& J, h5 U* j( s *priceny &pricen
' z& b, [0 K6 ~# `0 S. W % W2 L% l2 w0 t& B
" p; p. ]; d: \( m# [ t5 {) y0 A& A3 i( E
*-------------------------graph------------------
0 {0 ~; j9 n. p2 V , k& p! U. l% x. `
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). Q0 D8 z" p6 o& y* j: Q6 A3 C# w ^
2 J; v* d$ z, r' [, z* ---------可选项目----------------------0 T" H0 W! v, I- V3 n
*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean))
5 h& K$ Z& E8 C# G}3 O2 j) e3 E7 ~% H4 z
end
0 o+ y9 R. c- w2 C7 J; l6 r6 w |
|