Hi all,

I have the following situation:

The variables I have selected for a regression contain values for the years 1999-2011, except for the binary variable "poolacc"(= does the property has a swimming pool?) for which I have only values for the year 2011. I believe that I have to copy the same values of 2011 to the other years before (1999-2010).

How can I fill in the dots for years 1999-2010 of this variable 'poolacc' with the values of this particular year 2011 in an efficient way?

Here is some data with 3 variables; the id (I generated myself) ; hhmove=year moved into house; poolacc=presence of a pool (1= Yes, 2=No).

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float id int hhmove byte poolacc
  1 2001 .
  2 1999 .
  3 1999 .
  4 1999 .
  5 1999 .
  6 2000 .
  7 1999 .
  8 2000 .
  9 2000 .
 10 1999 .
 11 2000 .
 12 2001 .
 13 2000 .
 14 1999 .
 15 2001 .
 16 2001 .
 17 1999 .
 18 1999 .
 19 1999 .
 20 1999 .
 21 1999 .
 22 2000 .
 23 2001 .
 24 2000 .
 25 2000 .
 26 1999 .
 27 2000 .
 28 1999 .
 29 1999 .
 30 1999 .
 31 1999 .
 32 2000 .
 33 2001 .
 34 1999 .
 35 2000 .
 36 2000 .
 37 2000 .
 38 2001 .
 39 2000 .
 40 1999 .
 41 2001 .
 42 1999 .
 43 2001 .
 44 2001 .
 45 2000 .
 46 2001 .
 47 2001 .
 48 2001 .
 49 2000 .
 50 1999 .
 51 1999 .
 52 1999 .
 53 2000 .
 54 1999 .
 55 1999 .
 56 2001 .
 57 1999 .
 58 2001 .
 59 1999 .
 60 1999 .
 61 2000 .
 62 1999 .
 63 1999 .
 64 2001 .
 65 1999 .
 66 2000 .
 67 1999 .
 68 2000 .
 69 1999 .
 70 1999 .
 71 2001 .
 72 2000 .
 73 2000 .
 74 2000 .
 75 2001 .
 76 1999 .
 77 2001 .
 78 2000 .
 79 1999 .
 80 1999 .
 81 2000 .
 82 1999 .
 83 2001 .
 84 1999 .
 85 2001 .
 86 2001 .
 87 2000 .
 88 1999 .
 89 2000 .
 90 2000 .
 91 2000 .
 92 2000 .
 93 2000 .
 94 2000 .
 95 2001 .
 96 2000 .
 97 2001 .
 98 2000 .
 99 1999 .
100 2000 .
end
I tried the following code, but the data remained unchanged...:

Code:
bysort id (hhmove): replace poolacc = poolacc[_n -1] if poolacc ==. & hhmove < 2011
and

Code:
by id (hhmove), sort: replace poolacc= poolacc[_n-1] if poolacc>= . & hhmove<2011
(retrieved from the Stata website).

Does anyone know which code I need to put in to solve this issue?


Thanks in advance!