Dear all,
Below is a data set I want to reshape, from wide to long. It is the output from psmatch2, for each treated, I find 10 nearest neighbor, the variables _n1-_n10 keep the id for each matched observation.
And _id is the id of the treated observation. I do reshape because I want to create 10 observation for each treated firm, that is for _id =100781, I want to see 10 rows as shown below.
gvkey is also unique firm id.
My code here will not work because gvkey (firm identifier 1021 appear twice in the data, but they are in different years), reshape will not work if id is not unique. How do I get around this? My observation gvkey=1021 has two treatment one in each year 1997.
how can i fix this?
ultimately, I want to have a data set with each treated observation followed by 10 matched controls. most of the posting on psmatch2, or other matching routines, show treatment effects with outcome specified, but not discuss much about saving the paird data (match and treated) which is what i try to do here.
Thanks,
Rochelle
Below is a data set I want to reshape, from wide to long. It is the output from psmatch2, for each treated, I find 10 nearest neighbor, the variables _n1-_n10 keep the id for each matched observation.
Code:
clear input int(fyear gvkey) str7 _treated byte _weight long(_id _n1 _n2 _n3 _n4 _n5 _n6 _n7 _n8 _n9) 1997 1021 "Treated" 1 100781 55719 55720 55721 55722 55723 55724 55725 55726 55727 1995 1021 "Treated" 1 100369 20478 20479 20480 20481 20482 20483 20484 20485 20486 1995 1078 "Treated" 1 100376 20494 20495 20496 20493 20492 20497 20491 20490 20489 1995 1099 "Treated" 1 100631 43454 43455 43456 43457 43458 43459 43460 43461 43462 1995 1109 "Treated" 1 100869 60420 60421 60422 60423 60424 60425 60419 60426 60427 1997 1115 "Treated" 1 100787 55744 55745 55746 55747 55748 55749 55750 55751 55752 1998 1117 "Treated" 1 100686 44701 44702 44700 44699 44698 44697 44696 44703 44704 1987 1137 "Treated" 1 100593 41052 41053 41054 41055 41056 41051 41050 41049 41048 1994 1151 "Treated" 1 100718 55074 55075 55076 55077 55078 55079 55080 55081 55082 1995 1166 "Treated" 1 100532 35895 35896 35897 35898 35899 35900 35901 35902 35903 1996 1173 "Treated" 1 100756 55402 55403 55404 55405 55406 55407 55408 55409 55410 end
gvkey is also unique firm id.
Code:
input int(fyear gvkey) str7 _treated byte _weight long(_id nmatch) 1997 1021 "Treated" 1 100781 55719 1997 1021 "Treated" 1 100781 55720 1997 1021 "Treated" 1 100781 55721 1997 1021 "Treated" 1 100781 55722 1997 1021 "Treated" 1 100781 55723 1997 1021 "Treated" 1 100781 55724 1997 1021 "Treated" 1 100781 55725 1997 1021 "Treated" 1 100781 55726 1997 1021 "Treated" 1 100781 55727 1997 1021 "Treated" 1 100781 55728 end
Code:
reshape long _n, i(gvkey) j(nmatch)
ultimately, I want to have a data set with each treated observation followed by 10 matched controls. most of the posting on psmatch2, or other matching routines, show treatment effects with outcome specified, but not discuss much about saving the paird data (match and treated) which is what i try to do here.
Thanks,
Rochelle
Comment