Stata keeping even years

121 views Asked by At

If I have data for every year of 1932 to 2012, how do I keep only the even number years from 1946 to 2012 in Stata? I've tried the following:

keep if year == 1946(2)2012 

But it doesn't seem to help.

1

There are 1 answers

1
Roberto Ferrer On BEST ANSWER

The error you receive with your code is: unknown function 1946(). Stata thinks 1946 is a function because it is followed by an opening parenthesis. It is expecting an expression and functions can be part of an expression. However, you are giving it a numlist (help numlist), and that is not allowed.

An example that works:

clear 
set more off

*----- example data -----

set obs 81
egen year = seq(), from(1932) to(2012)

list

*----- what you want -----

keep if mod(year,2) == 0 & year >= 1946

list

Note I used a (legal) function, namely, the modulo function.