I have the dataset below: unique id of individuals (variable called pf_id), national id of individuals (variable called pf_cns), over different years and months (variables called ano_adm and mes_adm). Variable pf_id is unique for each individual while sometimes variable pf_cns is missing for some years/months or show different values across years/months. When this is the case, I would like to replace the missing variable pf_cns by its most recent non-missing value for the same individual (based on pf_id). I know I should use "bys" but I am not sure how as there is no standardisation for when variable pf_cns is missing.

Code:
clear 
input ano_adm mes_adm pf_id double pf_cns
ano_adm    mes_adm    pf_id    pf_cns
2008    1    8    980016003260284
2008    2    8    .
2008    3    8    .
2008    4    8    .
2008    5    8    .
2008    6    8    .
2008    7    8    .
2008    8    8    .
2008    9    8    .
2008    10    8    .
2008    11    8    .
2008    12    8    .
2009    1    8    .
2009    2    8    .
2013    3    14    .
2013    4    14    .
2013    5    14    .
2013    6    14    .
2013    7    14    .
2013    8    14    .
2013    9    14    .
2013    10    14    .
2013    11    14    700002890273401
2013    12    14    700002890273401
2014    1    14    700002890273401
2008    4    15    .
2008    5    15    980016282205587
2008    6    15    980016282205587
2008    7    15    980016282205587
2008    8    15    980016282205587
2008    9    15    980016282205587
2008    10    15    980016282205587
2008    11    15    980016282205587
2008    12    15    980016282205587
2009    1    15    980016282205587
2009    2    15    980016282205587
2009    3    15    980016282205587
2009    4    15    980016282205587
2009    5    15    980016282205587
2009    6    15    980016282205587
2009    7    15    980016282205587
2009    8    15    980016282205587
2008    1    29    980016278876235
2008    2    29    .
2008    3    29    980016280817801
2008    4    29    980016280817801
2008    5    29    980016280817801
2008    6    29    980016280817801
2008    7    29    980016280817801
2008    8    29    980016280817801

format pf_cns %15.0f