Richard Hofler can you help? As I believe you were the author of this code
re post 5 on here https://www.statalist.org/forums/for...score-matching

i am trying to understand this code which the user recommends using after psmatch2 to plot to kdensity curves to identify control when treatment = 0 and dup >1.


Code:
gen match=_n1  
replace match=_id if match==.
i understand that a new variable called match =_n1 where STATA gives value of 1 for 1st observation, 2 for 2nd and so on. So if there are 400 observations the last onservation should be 400.

therefore why should there be a missing value ?
why does the user say if match =. Replace with _id.
how can there be a missing value if the match variable generated is = _n1

the user then goes on to use the code below to identify the duolicates and therefor identify the matched (i think)
Code:
duplicates tag match, gen(dup)
i would like to know why the user uses this code as part of his controls to plot a kdensity graph. Its 4am and i’m still thinking about this. I have asked chatgpt who also didnt give me a solution. And emailed several people about this. Appreciate some insignt.