0

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.

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
Joe Maj
  • 1
  • 3

1 Answers1

0

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.

Roberto Ferrer
  • 11,024
  • 1
  • 21
  • 23
  • Perhaps more accurate that Stata thinks you think 1946() is a function ... Stata knows that 1946() is not a function. – Nick Cox Nov 12 '14 at 01:27