I have a dataset like this,
clear
input byte (id state)
1 0
1 .
1 1
2 0
2 .
2 1
3 0
3 .
3 1
3 .
3 .
3 .
3 0
3 .
4 0
4 .
4 .
4 .
4 .
4 .
4 .
4 1
end
I want to replace the missing values with the preceding value within id.
For example, when id==3, the filled data looks like as follows,
3 0
3 0
3 1
3 1
3 1
3 1
3 0
3 0
Can someone help me with Stata code?
Thank you!
clear
input byte (id state)
1 0
1 .
1 1
2 0
2 .
2 1
3 0
3 .
3 1
3 .
3 .
3 .
3 0
3 .
4 0
4 .
4 .
4 .
4 .
4 .
4 .
4 1
end
I want to replace the missing values with the preceding value within id.
For example, when id==3, the filled data looks like as follows,
3 0
3 0
3 1
3 1
3 1
3 1
3 0
3 0
Can someone help me with Stata code?
Thank you!

Comment