Bookmark and Share

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: nested loop for mean and median

From   Nahla Betelmal <>
Subject   st: nested loop for mean and median
Date   Mon, 29 Apr 2013 15:15:42 +0100

Dear Statalis,

I need to get the mean and median for some firms in a certain year
(2000-2012) and certain industry (73 industries). e.g. the mean and
median for assets for the firms operate in industry 6 in year 2004,
and so on. I tried the following nested loop but I got error (109).

p.s. I need the mean and median as new variables as they will be used
in further calculations.

foreach v of var  Assets Liab Income {
	forval y=2000/2012 {
			 forval  i= 1/73 {
				qui su `v' if  fyear==`y'& sic==`i'& country==1
				gen mean_`v' = r(mean)
				gen median_`v' = r(median)

type mismatch

Many thanks

Nahla Betelmal
*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index