��모(Byungmo Kim) wrote:
> In my dataset,
> each observaion has 23 variables ( year name fiscalyear v1 v2 v3
> ......... v20 )
>
> I'd like to make vars of standard deviation of sequential 10 variables.
>
> in other words,
>
> new variables ----------- standard deviation of 10 variables (
> for v1 to v10 ) --> std1 standard deviation of 10 variables ( for v2 to
> v11 ) --> std2 standard deviation of 10 variables ( for v3 to v12 ) -->
> std3 .
> .
> .
> .
> standard deviation of 10 variables ( for v11 to v20 ) --> std11
>
> how can i do this?? please teach me ..
> i'm very new to stata.
One way to do this would be
. egen std1to10 = rstd(v1-v10)
. egen std2to11 = rstd(v2-v11)
...
etc
which requires that your variables are in the right order. (You may change the
order of variables with -order-)
You may also put this in a loop, to save some typing. There are several ways
to do this, but one is:
. forv i = 1/14 {
. local j = `i' + 9
. egen std`i'to`j' = rstd(v`i'-v`j')
.}
And, finally: For problems like that it is often better to change the data
structure from wide to long, and to work with -by varlist:-. However this
would require some more teaching. To start with, take a look at
. h reshape
Also note the excellent introduction in the Stata Journal article by Cox:
SJ-2-1 pr0004 . . . . . . . . . . Speaking Stata: How to move step by: step
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
Q1/02 SJ 2(1):86-102 (no commands)
explains the use of the by varlist : construct to tackle
a variety of problems with group structure, ranging from
simple calculations for each of several groups to more
advanced manipulations that use the built-in _n and _N
regards
uli
--
[email protected]
+49 (030) 25491-361
*
* 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/