Hello everyone,

I'm having a problem commanding a local to do a function. The idea of the whole loop is to match a control firm to a treatment firm, append onto the matched_pairs dataset, and then drop the control firm such that it cannot match to any other treatment firms. The code is shown below:

Code:
 append using matched_pairs.dta, nolabel
                        
                                                    save matched_pairs.dta, replace
                                                    local abc bncusip == _N
                                                    use matching_firms`i'.dta, replace
                                                    drop if bncusip == abc, force
                                                    save matching_firms`i'.dta, replace
The issue is with the local command: I want a create a local command abc that identifies the last observation in the bncusip column, so that I can identify that observation in the matching_firms dataset and drop it.

Can anyone help fixing this local command? Thank you!