Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: nested calculations

 From Fabio Zona To statalist@hsphsun2.harvard.edu Subject st: nested calculations Date Thu, 2 Dec 2010 22:04:21 +0100 (CET)

```Hi All,
I have another little problem: promise it is the last one for today!

I have the list below. For each firm, I have to calculate the standard deviation for every variable (e.g., for Var 1) referring to the 4 quarters of each year!
Below you find both the starting matrix and the expected one.

Please, help! (I think this might be easier)

STARTING MATRIX OF VAR/OBS
firm   year  quarter  	Var1	Var2
1	1	1
1	1	2
1	1	3
1	1	4
1	2	1
1	2	2
1	2	3
1	2	4
1	3	1
1	3	2
1	3	3
1	3	4
2	1	1
2	1	2
2	1	3
2	1	4
2	2	1
2	2	2
2	2	3
2	2	4
2	3	1
2	3	2
2	3	3
2	3	4

EXPECTED MATRIX OF VAR/OBS
firm   year  stddev_Var1
1       1        number
1       2
1       3
2       1
2       2
2       3

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```