Hi all,
For the panel data as below, I want to replace 0-or-missing values to the maximum value within the same year.
I've tried loop with by option but it isn't very clear to me combining those with max function.
year id var1 var2 var3 ...
1999 14291 130 . 6
1999 20186 0 705 0
2000 14291 130 0 .
2000 20186 0 819 .
2001 14291 135 0 .
2001 20186 0 769 .
2002 14291 135 0 22
2002 20186 0 783 0
to...
year id var1 var2 var3
1999 14291 130 705 6
1999 20186 130 705 6
2000 14291 130 819 .
2000 20186 130 819 .
2001 14291 135 769 .
2001 20186 135 769 .
2002 14291 135 783 22
2002 20186 135 783 22
For the panel data as below, I want to replace 0-or-missing values to the maximum value within the same year.
I've tried loop with by option but it isn't very clear to me combining those with max function.
year id var1 var2 var3 ...
1999 14291 130 . 6
1999 20186 0 705 0
2000 14291 130 0 .
2000 20186 0 819 .
2001 14291 135 0 .
2001 20186 0 769 .
2002 14291 135 0 22
2002 20186 0 783 0
to...
year id var1 var2 var3
1999 14291 130 705 6
1999 20186 130 705 6
2000 14291 130 819 .
2000 20186 130 819 .
2001 14291 135 769 .
2001 20186 135 769 .
2002 14291 135 783 22
2002 20186 135 783 22
Comment