Hi nick,
Thanks very much. I was looking just for this answer!! i.e on how to put
the required number of observations into one group and then do the
calculations by group... Infact I have four or five variables on which I
have to do this...for which I can now use the foreach var...
I must say this is an excellent learning resource! Thanks to people like
you...
Regards
Rajesh
Address : Room F12, Xfi-Centre for Finance and Investment
University of Exeter, Streatham Court, EX4 4PU
Tel(office) : 01392262544
Tel(mobile) : 07770565093
Alt.email : [email protected]
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of n j cox
Sent: 17 February 2006 16:47
To: [email protected]
Subject: Re: st: FW: grouping observations and performing cals
Yes, there are (much) easier ways to do this.
Your basic strategy of getting mean and standard
deviation first is I think correct.
I understand that you want disjoint windows.
Your example is of window length 2. (I presume
that it is just a toy example. I would not
put much store by sds of pairs of values.
Also if the sd is zero, your ratio is indeterminate.)
You can coarsen your time variable by
gen T = floor(time/2)
0 and 1 map to 0, 2 and 3 map to 1, etc.
Then it is
egen mean = mean(X), by(T)
egen sd = sd(X), by(T)
gen unstablemeasure = mean/sd
This can be generalised to window lengths
other than 2 and you can offset time
first.
Nick
[email protected]
Rajesh Tharyan
I have some data in the following format
Time X
-5 2
-4 3
-3 2
-2 4
1 1
0 2
1 2
2 1
3 2
4 2
5 1
I need to compute y= Mean(X)/SD(X) for different time windows.
For example,
-5,-4 would be window 1
-3,-2 would be window 2 etc.
My present solution is this ( example for window 1)
Egen a=mean(X) if time>=-5 & time<=-4 (and so on for all the different
windows)
Egen b=sd(x) if if time>=-5 & time<=-4 (and so on for all the different
windows)
Gen y=a/b
Is there an easier way to do this???
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/