Hi all,

I have the following situation:
Code:
     +--------------------------------+
     |    pidp   wave       max_class |
     |--------------------------------|
  1. |  280165      2   Service class |
  2. |  280165      3               . |
  3. |  541285      3               . |
  4. |  541965      3               . |
  5. |  665045      3               . |
     |--------------------------------|
  6. |  956765      2               . |
  7. |  956765      3               . |
  8. |  987365      2               . |
  9. |  987365      3               . |
 10. | 1114525      2               . |
     |--------------------------------|
 11. | 1126765      2               . |
 12. | 1558565      2   Working class |
 13. | 1558565      3               . |
 14. | 1833965      2               . |
 15. | 1833965      3               . |
     +--------------------------------+
I want to replace, for example, the missing in line 2 with "Service class" (encoded with value 6) or similarly the missing value in line 13 with "Working class". That is, within each unique identifier (pidp) and wave, I want to replace the missing with the first existing observation and of course keep it missing if it's actually missing.
For this purpose, I'm using the following code:

Code:
 bysort pidp wave (max_class) : replace max_class=max_class[1]
However, the output is "0 real changes made" and I cannot figure out why is this the case. Indeed, if I simply try a "disp max_class[1] if pidp==280165 & wave==2" it correctly reports 6.
Do you have any hints?

Thanks for your support