Hi all,
Please consider the following example data:
Now, I want to join parts of trialdata2 to trialdata1, based on the following condition: keep only those observations from trialdata2 that have the year-school combination available in trialdata1, and then append those observations to trialdata1 to form trialdata3 as below:
I generated the trialdata3 by
But ideally I want the code to select these observations from trialdata2 based on the combination from trialdata1, and create the subset data, which I then append to trialdata1 and create trialdata3.
I tried
but that did not give desired result.
Would appreciate any help, thanks
Please consider the following example data:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str3 id float year str1 pcd float school "111" 2011 "" 123 "111" 2012 "" 124 "111" 2013 "" 124 "112" 2010 "" 123 "112" 2011 "" 123 "112" 2012 "" 123 "113" 2014 "" 126 "113" 2015 "" 127 "113" 2016 "" 128 "113" 2017 "" 128 end save "trialdata1.dta"
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str3 id float year str3 pcd float school "111" 2011 "" 123 "111" 2012 "" 124 "111" 2013 "" 124 "112" 2010 "" 123 "112" 2011 "" 123 "112" 2012 "" 123 "113" 2014 "" 126 "113" 2015 "" 127 "113" 2016 "" 128 "113" 2017 "" 128 "114" 2013 "AAA" 123 "114" 2014 "AAB" 128 "114" 2015 "AAA" 124 "115" 2014 "AAA" 124 "115" 2015 "AAC" 127 "115" 2016 "AAB" 128 "115" 2017 "AAC" 128 "116" 2015 "AAC" 127 "116" 2016 "AAA" 124 "116" 2017 "AAB" 126 end save "trialdata2.dta"
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str3 id float year str3 pcd float school "115" 2015 "AAC" 127 "115" 2016 "AAB" 128 "115" 2017 "AAC" 128 "116" 2015 "AAC" 127 end
Code:
keep if year==2011 & school==123|year==2012 & school==124|year==2013 & school==124|year==2010 & school==123|year==2011 & school==123|year==2012 & school==123|year==2014 & school==126|year==2015 & school==127|year==2016 & school==128|year==2017 & school==128
I tried
Code:
joinby year school
Would appreciate any help, thanks
Comment