1
votes
year
  0
  1
  6
....
(omit)
....
 77
 90
....
(omit)
....

The "year" is a numeric variable. I need to add "200" before the 1-digit values, and "19" before the 2-digit values.

year
2000
2001
2006
....
1977
1990
....

How can I do this in Stata?

1

1 Answers

2
votes

Be careful: the variable might be byte and that will bite.

This should work:

 gen year2 = cond(year < 10, 2000 + year, 1900 + year) 
 tab year2 

If year2 looks good,

 drop year 
 rename year2 year