Hello,
I am attempting to combine two data sets, one of which has annual data and the other has monthly data for only a few select months per year. however, when I go to do the merge, I keep getting the information that the data between the Master and the Using are not merged (note: this is not an error, just none of the data is merged. See below) This is my first time really dealing with Stata with regards to transforming strings into dates and combining disparate data sets. I will break this post up into multiple parts in an attempt to see where my error lies.
First, I am importing the annual dataset, which is an Excel file, into Stata:
Code:
import excel "C:\Users\jmurp\Desktop\snappolicyindexdata.xls", sheet("Sheet1") firstrow case(lower) allstring
. rename statefipscode state
. destring state, replace
state: all characters numeric; replaced as byte
. gen year2 = yearly(year, "Y")
This gives me the following:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str4 year float year3 byte state str17 unweightedtransactioncostinde
"1996" 1996 1 ".7873089909553528"
"1997" 1997 1 ".9619993567466736"
"1998" 1998 1 ".8730361461639404"
"1999" 1999 1 ".8742402791976929"
"2000" 2000 1 ".7630371451377869"
"2001" 2001 1 ".7088135480880737"
"2002" 2002 1 ".8338995575904846"
"2003" 2003 1 ".8852885365486145"
"2004" 2004 1 "1.331129312515259"
"2005" 2005 1 "2.017022132873535"
"2006" 2006 1 "2.138442039489746"
"2007" 2007 1 "2.138442039489746"
"2008" 2008 1 "2.020892381668091"
"2009" 2009 1 "2.138442039489746"
"2010" 2010 1 "2.138442039489746"
"2011" 2011 1 "2.138442039489746"
"2012" 2012 1 "2.72177529335022"
"2013" 2013 1 "3.138442039489746"
"2014" 2014 1 "3.138442039489746"
"1996" 1996 2 "1.010496377944946"
"1997" 1997 2 "1.010496377944946"
"1998" 1998 2 ".9321550130844116"
"1999" 1999 2 "1.138442158699036"
"2000" 2000 2 ".9234683513641357"
"2001" 2001 2 ".9556993842124939"
"2002" 2002 2 "1.138442158699036"
"2003" 2003 2 "1.138442158699036"
"2004" 2004 2 "1.804209351539612"
"2005" 2005 2 "2.104795455932617"
"2006" 2006 2 "1.78836977481842"
"2007" 2007 2 "2.138442039489746"
"2008" 2008 2 "2.138442039489746"
"2009" 2009 2 "2.138442039489746"
"2010" 2010 2 "2.138442039489746"
"2011" 2011 2 "2.138442039489746"
"2012" 2012 2 "2.083318948745728"
"2013" 2013 2 "1.87486743927002"
"2014" 2014 2 "1.784610509872437"
"1996" 1996 4 ".4647372663021088"
"1997" 1997 4 ".447535902261734"
"1998" 1998 4 ".4035578370094299"
"1999" 1999 4 ".3449657559394836"
"2000" 2000 4 ".3717425167560577"
"2001" 2001 4 ".4626551866531372"
"2002" 2002 4 ".5120731592178345"
"2003" 2003 4 "1.645817279815674"
"2004" 2004 4 "1.825965404510498"
"2005" 2005 4 "1.702130079269409"
"2006" 2006 4 "1.993517160415649"
"2007" 2007 4 "1.879157066345215"
"2008" 2008 4 "2.048694133758545"
"2009" 2009 4 "2.486948490142822"
"2010" 2010 4 "3.138442039489746"
"2011" 2011 4 "3.138442039489746"
"2012" 2012 4 "3.138442039489746"
"2013" 2013 4 "3.094571590423584"
"2014" 2014 4 "3.050700902938843"
"1996" 1996 5 ".6945005655288696"
"1997" 1997 5 ".7590163350105286"
"1998" 1998 5 ".7152066826820374"
"1999" 1999 5 ".6893616914749146"
"2000" 2000 5 ".900558352470398"
"2001" 2001 5 ".8908431529998779"
"2002" 2002 5 ".7171991467475891"
"2003" 2003 5 "1.066809296607971"
"2004" 2004 5 "2.086622953414917"
"2005" 2005 5 "2.069708347320557"
"2006" 2006 5 "1.882163643836975"
"2007" 2007 5 "2.101803302764893"
"2008" 2008 5 "1.930241346359253"
"2009" 2009 5 "1.86871075630188"
"2010" 2010 5 "1.953728437423706"
"2011" 2011 5 "2.764119386672974"
"2012" 2012 5 "2.827212572097778"
"2013" 2013 5 "2.890893220901489"
"2014" 2014 5 "3.006572246551514"
"1996" 1996 6 ".966708242893219"
"1997" 1997 6 ".8214213848114014"
"1998" 1998 6 ".7084873914718628"
"1999" 1999 6 ".7671941518783569"
"2000" 2000 6 ".8532009124755859"
"2001" 2001 6 ".9936713576316834"
"2002" 2002 6 "1.11318838596344"
"2003" 2003 6 ".9343733191490173"
"2004" 2004 6 "1.138442158699036"
"2005" 2005 6 "1.056789517402649"
"2006" 2006 6 "1.122111678123474"
"2007" 2007 6 "1.138442158699036"
"2008" 2008 6 ".974398672580719"
"2009" 2009 6 "1.072202682495117"
"2010" 2010 6 "1.221775531768799"
"2011" 2011 6 "2.138442039489746"
"2012" 2012 6 "2.138442039489746"
"2013" 2013 6 "2.285334348678589"
"2014" 2014 6 "2.940877437591553"
"1996" 1996 8 ".5168286561965942"
"1997" 1997 8 ".5018777847290039"
"1998" 1998 8 ".4973481297492981"
"1999" 1999 8 ".4887761473655701"
"2000" 2000 8 ".4511123597621918"
end
Is this correct so far?
I clean things up a little bit (in order to facilitate the merge, I think):
Code:
drop year
rename year2 year
save "C:\Users\jmurp\Dropbox\GMU\Dissertation\SNAP Costs and Take Up\VCL\tcindex.dta", replace
Now, I want to merge this dataset with another one that looks like this:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(year state stamp_fss_actual)
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 1
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 1
517 1 0
517 1 1
517 1 1
517 1 0
517 1 0
517 1 1
517 1 0
517 1 1
517 1 0
517 1 0
517 1 1
517 1 1
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 1
517 1 1
517 1 0
517 1 0
517 1 0
end
format %tm year
label values state state
label def state 1 "AL", modify
NB: this data set has monthly data for most states from February through December for 2003, 2006, and 2010.
Now, I try to merge the data like this and get the following:
Code:
merge m:1 year state using tcindex
Result # of obs.
-----------------------------------------
not matched 286,654
from master 285,685 (_merge==1)
from using 969 (_merge==2)
matched 0 (_merge==3)
-----------------------------------------
Obviously, I am doing something wrong. I am under the impression that merging annual and monthly data is possible. In searching forums, I primarily see folks confusing m:1 and 1:1 merging and getting error messages of "not unique variables." Am I barking up the wrong tree?
Many thanks for the help!