We say that a set of integers, A, is hyperarithmetically (recursively) encodable, if every infinite set of integers X contains an infinite subset Y in which A is hyperarithmetical (recursive). We show that the recursively encodable sets are precisely the hyperarithmetic sets. Let
σ
\sigma
be the closure ordinal of a universal
Σ
1
1
\Sigma _1^1
inductive definition. Then A is hyperarithmetically encodable iff it is constructible before stage
σ
\sigma
. We also prove an effective version of the Galvin-Prikry results that open sets, and more generally Borel sets, are Ramsey, and in the case of open sets prove that our improvement is optimal.