Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Merge command does get matches

    Hi;

    I have panel-data and like to add some information specified to each company and year by merging both data samples.
    Unfortunately I receive 0 matched observation so the key variables might have a difference?
    I checked my observation and there are some matching ds_codes for sure.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str7 ds_code float year
    "130062" 7
    "130062" 9
    "130062" 10
    "130062" 12
    "130062" 14
    "130062" 8
    "130062" 11
    "130062" 13
    "130298" 9
    "130298" 5
    "130298" 8
    "130298" 1
    "130298" 12
    "130298" 3
    "130298" 7
    "130298" 13
    "130298" 14
    "130298" 2
    "130298" 6
    "130298" 10
    "130298" 11
    "130298" 4
    "130375" 12
    "130375" 8
    "130375" 9
    "130375" 11
    "130375" 14
    "130375" 7
    "130375" 10
    "130375" 13
    "130775" 8
    "130775" 7
    "130775" 2
    "130775" 1
    "130775" 14
    "130775" 11
    "130775" 5
    "130775" 13
    "130775" 4
    "130775" 6
    "130775" 12
    "130775" 10
    "130775" 9
    "130775" 3
    "13466Q" 12
    "13466Q" 9
    "13466Q" 7
    "13466Q" 13
    "13466Q" 14
    "13466Q" 8
    "13466Q" 10
    "13466Q" 11
    "13471D" 8
    "13471D" 7
    "13471D" 9
    "13471D" 14
    "13471D" 12
    "13471D" 10
    "13471D" 13
    "13471D" 11
    "13906D" 7
    "13906D" 10
    "13906D" 1
    "13906D" 11
    "13906D" 6
    "13906D" 3
    "13906D" 13
    "13906D" 4
    "13906D" 8
    "13906D" 5
    "13906D" 14
    "13906D" 2
    "13906D" 12
    "13906D" 9
    "13950L" 12
    "13950L" 7
    "13950L" 8
    "13950L" 11
    "13950L" 13
    "13950L" 4
    "13950L" 3
    "13950L" 5
    "13950L" 14
    "13950L" 1
    "13950L" 10
    "13950L" 2
    "13950L" 6
    "13950L" 9
    "13951F" 13
    "13951F" 8
    "13951F" 7
    "13951F" 10
    "13951F" 9
    "13951F" 11
    "13951F" 14
    "13951F" 12
    "13967C" 1
    "13967C" 13
    "13967C" 8
    "13967C" 5
    end
    label values year year1
    label def year1 1 "2004", modify
    label def year1 2 "2005", modify
    label def year1 3 "2006", modify
    label def year1 4 "2007", modify
    label def year1 5 "2008", modify
    label def year1 6 "2009", modify
    label def year1 7 "2010", modify
    label def year1 8 "2011", modify
    label def year1 9 "2012", modify
    label def year1 10 "2013", modify
    label def year1 11 "2014", modify
    label def year1 12 "2015", modify
    label def year1 13 "2016", modify
    label def year1 14 "2017", modify

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str7 ds_code float year
    "130062" 1999
    "130062" 2000
    "130062" 2001
    "130062" 2002
    "130062" 2003
    "130062" 2004
    "130062" 2005
    "130062" 2006
    "130062" 2007
    "130062" 2008
    "130062" 2009
    "130062" 2010
    "130062" 2011
    "130062" 2012
    "130062" 2013
    "130062" 2014
    "130062" 2015
    "130062" 2016
    "130062" 2017
    "130062" 2018
    "130063" 2015
    "130063" 2016
    "130063" 2017
    "130065" 1999
    "130065" 2000
    "130065" 2001
    "130065" 2002
    "130065" 2003
    "130065" 2004
    "130065" 2005
    "130065" 2006
    "130065" 2007
    "130065" 2008
    "130065" 2009
    "130065" 2010
    "130065" 2011
    "130065" 2012
    "130065" 2013
    "130065" 2014
    "130065" 2015
    "130065" 2016
    "130065" 2017
    "130066" 2015
    "130066" 2016
    "130066" 2017
    "130067" 2015
    "130067" 2016
    "130067" 2017
    "130072" 2015
    "130072" 2016
    "130072" 2017
    "130073" 2015
    "130073" 2016
    "130073" 2017
    "130079" 1999
    "130079" 2000
    "130079" 2001
    "130079" 2002
    "130079" 2003
    "130079" 2004
    "130079" 2005
    "130079" 2006
    "130079" 2007
    "130079" 2008
    "130079" 2009
    "130079" 2010
    "130079" 2011
    "130079" 2012
    "130079" 2013
    "130079" 2014
    "130079" 2015
    "130079" 2016
    "130079" 2017
    "130083" 2015
    "130083" 2016
    "130083" 2017
    "130086" 1999
    "130086" 2000
    "130086" 2001
    "130086" 2002
    "130086" 2003
    "130086" 2004
    "130086" 2005
    "130086" 2006
    "130086" 2007
    "130086" 2008
    "130086" 2009
    "130086" 2010
    "130086" 2011
    "130086" 2012
    "130086" 2013
    "130086" 2014
    "130086" 2015
    "130086" 2016
    "130086" 2017
    "130088" 1999
    "130088" 2000
    "130088" 2001
    "130088" 2002
    "130088" 2003
    end
    Thank you very much in adavance!

  • #2
    try adding 2003 to the year variable in the first data set

    Comment


    • #3
      Got it solved, thanks for your answer

      Comment


      • #4
        Elaborating on Øyvind's answer, the problem with your first dataset is that it originally had the year as a string variable, and you used the encode command to create a numeric variable.

        The encode command is designed for assigning numerical codes to non-numeric strings like "France", "Germany", "United States". The output of help encode instructs us

        Do not use encode if varname contains numbers that merely happen to be stored as strings; instead, use generate newvar = real(varname) or destring; see real() or [D] destring.
        You should review your work and see if you have made this mistake elsewhere. The workaround to correct the data will fix this case, although my preference would be to correct the program with the error and rerun it, and any subsequent programs. That way if you were use that program on new data, or as the basis of another program to process different data, you will not repeat the mistake.

        Comment

        Working...
        X