I was asked to provide "more detail" on a problem that is occurring when using the 1:m merge function in Stata. I have two datasets on Louisiana parishes. One has 592 observations (37 parishes and 15 years of data), the other has all 64 parishes and 18 years of data, or 1216 rows of data.
PHP Code:
 summarize county county_year empstable hirenewseparator(0)

    
Variable |        Obs        Mean    StdDev.       Min        Max
-------------+---------------------------------------------------------
      
county |      1,216        32.5    18.48055          1         64
 county_year 
|      1,216       608.5    351.1733          1       1216
   empstable 
|      1,152    24038.05     41861.7        785     235928
     hirenew 
|      1,134    5707.772    10375.46         99      65927 
This the the longer dataset.

The shorter dataset:
PHP Code:
 summarize county county_year empstable avgstateincentiveseparator(0)

    
Variable |        Obs        Mean    StdDev.       Min        Max
-------------+---------------------------------------------------------
      
county |        592          19    10.68611          1         37
 county_year 
|        592       296.5      171.04          1        592
   empstable 
|        592    32501.51    50693.93        997     240370
avgstatein
~|        592    .0324106    .0012255      .0301     .03366 
When I attempt to merge avgstateincentive to the longer dataset with all parishes the merge "runs out" after 592 observations and the data from the avgstateincentive variable is not matched correctly with the correct parish name. Prior to doing this, I created a group variable to uniquely identify county name by year
Code:
egen float county_year = group(county year)
The merge code I'm using is
Code:
 merge 1:m year county using "/Users/daviadowney/Desktop/Local Government Studies 2020/6_10_20_RevisedData2020.dta", keepusing(avgstateincentive) force

    Result                           # of obs.
    -----------------------------------------
    not matched                           624
        from master                       624  (_merge==1)
        from using                          0  (_merge==2)

    matched                               592  (_merge==3)
    -----------------------------------------
For example, Avoyelles is not in the shorter dataset, yet the avgstateincentive variable is connected to these data after the merge is run which is incorrect. The resulting merge looks like this:

----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double avgstateincentive long county float county_year int year
.03189 5  84 2007
.03308 5  89 2012
.03332 5  90 2013
.03182 5  85 2008
.03273 5  82 2005
.03011 5  78 2001
.03011 6  97 2001
.03273 6 101 2005
     . 6 113 2017
.03332 6 110 2014
.03246 6  99 2003
     . 6 114 2018
.03189 6 103 2007
.03365 6 102 2006
.03182 6 104 2008
.03366 6 107 2011
.03342 6 106 2010
.03332 6 111 2015
     . 6 112 2016
.03274 6 100 2004
.03011 6  98 2002
end
label values county countyname
label def countyname 5 "Avoyelles", modify
label def countyname 6 "Beauregard", modify
County names in longer dataset:
Code:
list county if year==2000

      +----------------------+
      |               county |
      |----------------------|
  16. |               Acadia |
  32. |                Allen |
  57. |            Ascension |
  61. |           Assumption |
  88. |            Avoyelles |
      |----------------------|
 114. |           Beauregard |
 117. |            Bienville |
 144. |              Bossier |
 154. |                Caddo |
 176. |            Calcasieu |
      |----------------------|
 197. |             Caldwell |
 219. |              Cameron |
 241. |            Catahoula |
 261. |            Claiborne |
 273. |            Concordia |
      |----------------------|
 291. |              De Soto |
 318. |     East Baton Rouge |
 326. |         East Carroll |
 360. |       East Feliciana |
 363. |           Evangeline |
      |----------------------|
 385. |             Franklin |
 417. |                Grant |
 426. |               Iberia |
 456. |            Iberville |
 457. |              Jackson |
      |----------------------|
 481. |            Jefferson |
 508. |      Jefferson Davis |
 523. |              LaSalle |
 544. |            Lafayette |
 567. |            Lafourche |
      |----------------------|
 586. |              Lincoln |
 597. |           Livingston |
 610. |              Madison |
 630. |            Morehouse |
 657. |         Natchitoches |
      |----------------------|
 668. |              Orleans |
 700. |             Ouachita |
 709. |          Plaquemines |
 730. |        Pointe Coupee |
 746. |              Rapides |
      |----------------------|
 767. |            Red River |
 784. |             Richland |
 814. |               Sabine |
 830. |          St. Bernard |
 842. |          St. Charles |
      |----------------------|
 870. |           St. Helena |
 885. |            St. James |
 911. | St. John the Baptist |
 917. |           St. Landry |
 947. |           St. Martin |
      |----------------------|
 962. |             St. Mary |
 978. |          St. Tammany |
 993. |           Tangipahoa |
1012. |               Tensas |
1035. |           Terrebonne |
      |----------------------|
1060. |                Union |
1065. |            Vermilion |
1085. |               Vernon |
1104. |           Washington |
1133. |              Webster |
      |----------------------|
1145. |     West Baton Rouge |
1170. |         West Carroll |
1197. |       West Feliciana |
1215. |                 Winn |
      +----------------------+
County names in shorter dataset:
Code:
. list county if year==2000

     +------------------+
     |           county |
     |------------------|
  1. |           Acadia |
 17. |            Allen |
 33. |        Ascension |
 49. |       Assumption |
 65. |       Beauregard |
     |------------------|
 81. |        Calcasieu |
 97. |          Cameron |
113. | East Baton Rouge |
129. |   East Feliciana |
145. |       Evangeline |
     |------------------|
161. |           Iberia |
177. |        Iberville |
193. |        Jefferson |
209. |  Jefferson Davis |
225. |        Lafayette |
     |------------------|
241. |        Lafourche |
257. |       Livingston |
273. |          Orleans |
289. |      Plaquemines |
305. |     PointeCoupee |
     |------------------|
321. |           Sabine |
337. |        StBernard |
353. |        StCharles |
369. |         StHelena |
385. |          StJames |
     |------------------|
401. |    StJohnBaptist |
417. |         StLandry |
433. |         StMartin |
449. |           StMary |
465. |        StTammany |
     |------------------|
481. |       Tangipahoa |
497. |       Terrebonne |
513. |        Vermilion |
529. |           Vernon |
545. |       Washington |
     |------------------|
561. |   WestBatonRouge |
577. |    WestFeliciana |
     +------------------+
Apologies for the long post, I'm hoping this post is detailed enough to garner useful input on how to proceed.