Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: Create variable with historic means

From   Sergio <>
Subject   st: Create variable with historic means
Date   Tue, 16 Aug 2011 09:33:34 -0700 (PDT)


I'm trying to create a new variable that contains the historical means of
CATCH, but only using the previous years.  My dataset looks something like

2004       2           1           1          1
2005       3           2           3          2
...          ...          ...          ...        ...

In this case I want to create a new variable that will take the value of the
mean catch for the previous years (2004 and 2005) by ZONE, WAVE and MODE,
but not use any of the 2006 observations to calculate the means.  Its OK if
the variable is created for the previous years as well, as I plan to drop
those observations once I can get the new variable.

I have been able to create a table that gives me the mean of CATCH by ZONE,
WAVE and MODE using:

table zone wave mode if (year<2006), contents (m catch) 

And I can create a variable that has the means, using 2006 data, with:

by zone wave mode, sort: egen hckr = mean(catch)

When I try to create the variable using only the previous years, I have

by zone wave mode, sort: egen hckr = mean(catch) if(year<2006)

But it just gives me missing values for all observations from year 2006.

I would really appreciate any tips you can offer.

Sergio Alvarez
Food and Resource Economics Department
University of Florida

View this message in context:
Sent from the Statalist mailing list archive at
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index