Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: FW: grouping observations and performing cals


From   n j cox <[email protected]>
To   [email protected]
Subject   Re: st: FW: grouping observations and performing cals
Date   Fri, 17 Feb 2006 16:47:26 +0000

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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index