Hi,
I have a panel for factories with unique IDs that stop being unique in the year 2007 (the last data point is 2013). My goal is to use the end of year inventory for 2007 (MPMVAP & year==2007) and match it to the start of year inventory of the following year (MPMVAF & year==2008), and continue to do that until 2013. The problem is I don't know for a fact that the values will be the same, or that there won't be more than one factory that has the same value. So, for my first try, I'd like to see how many matches there are for final year inventory and subsequent year start inventory and to be able to identify them through an id variable that I generated which is unique (id).
I found on an old Statalist message (https://www.stata.com/statalist/arch.../msg01035.html) a sort of similar situation and modified the code without success.
Below is the modification I wrote. The loop only makes one replacement and keeps the rest as missing values.
gen match_count = .
gen match_id = .
forval i = 2007/2013 {
su id if (MPMVAF == MPMVAP[`i'] & (ANIO == ANIO[`i'] - 1)), meanonly
replace match_id = r(min) in `i'
replace match_count = r(N) in `i'
}
thanks for your help!
I have a panel for factories with unique IDs that stop being unique in the year 2007 (the last data point is 2013). My goal is to use the end of year inventory for 2007 (MPMVAP & year==2007) and match it to the start of year inventory of the following year (MPMVAF & year==2008), and continue to do that until 2013. The problem is I don't know for a fact that the values will be the same, or that there won't be more than one factory that has the same value. So, for my first try, I'd like to see how many matches there are for final year inventory and subsequent year start inventory and to be able to identify them through an id variable that I generated which is unique (id).
I found on an old Statalist message (https://www.stata.com/statalist/arch.../msg01035.html) a sort of similar situation and modified the code without success.
Below is the modification I wrote. The loop only makes one replacement and keeps the rest as missing values.
gen match_count = .
gen match_id = .
forval i = 2007/2013 {
su id if (MPMVAF == MPMVAP[`i'] & (ANIO == ANIO[`i'] - 1)), meanonly
replace match_id = r(min) in `i'
replace match_count = r(N) in `i'
}
thanks for your help!
Comment