Hi I am aware there are other posts around using the -rangejoin- command and which discuss reshaping, but I can't find any which deal with the error I am getting when I try to reshape my data into long format after having successfully matched firms. (so the matching is fine, it is the reshaping of the data in preparation for regression testing I am struggling with).

I have used similar code before successfully a while ago, but for some reason I keep getting error at the moment and I'm not sure what to try. I attach below the code and a dataex example (I have a lot more variables in my actual data set).

As always, any advice is greatly appreciated.

The error I am getting at the moment is:

Code:
reshape long `vbles', i(pair_num) j(_p_status) string
(note: j = Location_U Location_p _U _p)
variable ShortTermLoansOverdraftsLocation_U implied name too long
But I have used these variables before and they weren't too long and it worked fine..

Code:
//MATCHING

preserve
keep if pe==1 & Year==2007
drop Year
tempfile treated
save `treated'
 
restore
keep if pe==0 & Year==2007
drop Year
tempfile controls
save `controls'

use `treated', clear
gen lower = TotalAssets*0.5
gen higher = TotalAssets*1.5

rangejoin TotalAssets lower higher using `controls', by(sic2)
keep if inrange(ROA1_w/ROA1_w_U, 1/1.50, 1.50)
keep if inrange(Leverage4_w/Leverage4_w_U, 1/1.50, 1.50)
gen long obs_no = _n
gen distance = (TotalAssets-TotalAssets_U)^2 + (ROA1_w - ROA1_w_U)^2
by BvDIDnumber (distance), sort: keep if _n <= 5

//RESHAPING


// Need to rename a couple of vars with long names

ren NetCurrentAssetsWorkingCapital NCAWC
ren OtherOperatingIncomeCostspreOP OOIC


// Reshaping data

ds *_U, not
local vbles `r(varlist)'
rename (`vbles') =_p
gen long pair_num = _n
reshape long `vbles', i(pair_num) j(_p_status) string
encode _p_status, gen(p_status)
drop _p_status



Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str136(Companyname BvDIDnumber) int Year double(FixedAssets ShortTermLoansOverdrafts NetCurrentAssetsWorkingCapital) byte firmtag float(DealYear ExitYear pe)
`""A" FOUNDATION"'                                                  "GB04667025" 2004             9.35                 .          1054.358 1 . . 0
`""A" FOUNDATION"'                                                  "GB04667025" 2005          104.859                 .            59.494 0 . . 0
`""A" FOUNDATION"'                                                  "GB04667025" 2006          130.834             -.083           -30.894 0 . . 0
`""A" FOUNDATION"'                                                  "GB04667025" 2007          437.626                 .           -98.655 0 . . 0
`""A" FOUNDATION"'                                                  "GB04667025" 2008          379.193          -256.028          -371.218 0 . . 0
`""A" FOUNDATION"'                                                  "GB04667025" 2009          346.185                 .           118.916 0 . . 0
`""A" FOUNDATION"'                                                  "GB04667025" 2010                .                 .                 . 0 . . 0
`""A" FOUNDATION"'                                                  "GB04667025" 2011                .                 .                 . 0 . . 0
`""BELL TELECOM" - AMERICAN TELEPHONE & WIRELESS LTD."'             "GB11040894" 2004                .                 .                 . 1 . . 0
`""BELL TELECOM" - AMERICAN TELEPHONE & WIRELESS LTD."'             "GB11040894" 2005                .                 .                 . 0 . . 0
`""BELL TELECOM" - AMERICAN TELEPHONE & WIRELESS LTD."'             "GB11040894" 2006                .                 .                 . 0 . . 0
`""BELL TELECOM" - AMERICAN TELEPHONE & WIRELESS LTD."'             "GB11040894" 2007                .                 .                 . 0 . . 0
`""BELL TELECOM" - AMERICAN TELEPHONE & WIRELESS LTD."'             "GB11040894" 2008                .                 .                 . 0 . . 0
`""BELL TELECOM" - AMERICAN TELEPHONE & WIRELESS LTD."'             "GB11040894" 2009                .                 .                 . 0 . . 0
`""BELL TELECOM" - AMERICAN TELEPHONE & WIRELESS LTD."'             "GB11040894" 2010                .                 .                 . 0 . . 0
`""BELL TELECOM" - AMERICAN TELEPHONE & WIRELESS LTD."'             "GB11040894" 2011                .                 .                 . 0 . . 0
`""CARTREF NI" LIMITED"'                                            "GB02591631" 2004           44.871            -3.394           219.861 1 . . 0
`""CARTREF NI" LIMITED"'                                            "GB02591631" 2005           53.104            -3.741           301.669 0 . . 0
`""CARTREF NI" LIMITED"'                                            "GB02591631" 2006           50.465            -4.122           271.015 0 . . 0
`""CARTREF NI" LIMITED"'                                            "GB02591631" 2007           45.585            -4.119           228.077 0 . . 0
`""CARTREF NI" LIMITED"'                                            "GB02591631" 2008           41.076            -1.611           281.986 0 . . 0
`""CARTREF NI" LIMITED"'                                            "GB02591631" 2009           45.329                 .           350.692 0 . . 0
`""CARTREF NI" LIMITED"'                                            "GB02591631" 2010           52.884                 .           399.312 0 . . 0
`""CARTREF NI" LIMITED"'                                            "GB02591631" 2011           48.027                 .           555.383 0 . . 0
`""CHANNING HOUSE"INCORPORATED HIGHGATE"'                           "GB00063121" 2004          683.655                 .              .631 1 . . 0
`""CHANNING HOUSE"INCORPORATED HIGHGATE"'                           "GB00063121" 2005          847.657                 .             5.072 0 . . 0
`""CHANNING HOUSE"INCORPORATED HIGHGATE"'                           "GB00063121" 2006         1142.002                 .             3.949 0 . . 0
`""CHANNING HOUSE"INCORPORATED HIGHGATE"'                           "GB00063121" 2007         1050.021                 .              4.59 0 . . 0
`""CHANNING HOUSE"INCORPORATED HIGHGATE"'                           "GB00063121" 2008          414.735                 .           -19.686 0 . . 0
`""CHANNING HOUSE"INCORPORATED HIGHGATE"'                           "GB00063121" 2009          604.639                 .          -185.446 0 . . 0
`""CHANNING HOUSE"INCORPORATED HIGHGATE"'                           "GB00063121" 2010          975.998                 .          -449.195 0 . . 0
`""CHANNING HOUSE"INCORPORATED HIGHGATE"'                           "GB00063121" 2011         1299.518                 .           -31.494 0 . . 0
`""EL AL" ISRAEL AIRLINES LIMITED"'                                 "GBFC004087" 2004           643730            -41341            -94988 1 . . 0
`""EL AL" ISRAEL AIRLINES LIMITED"'                                 "GBFC004087" 2005           681274            -47863            -59529 0 . . 0
`""EL AL" ISRAEL AIRLINES LIMITED"'                                 "GBFC004087" 2006           589788            -53699           -105948 0 . . 0
`""EL AL" ISRAEL AIRLINES LIMITED"'                                 "GBFC004087" 2007           650474            -33276            -73343 0 . . 0
`""EL AL" ISRAEL AIRLINES LIMITED"'                                 "GBFC004087" 2008                .                 .                 . 0 . . 0
`""EL AL" ISRAEL AIRLINES LIMITED"'                                 "GBFC004087" 2009                .                 .                 . 0 . . 0
`""EL AL" ISRAEL AIRLINES LIMITED"'                                 "GBFC004087" 2010                .                 .                 . 0 . . 0
`""EL AL" ISRAEL AIRLINES LIMITED"'                                 "GBFC004087" 2011                .                 .                 . 0 . . 0
`""EMPEROR DIVERS" FOR DIVING ACTIVITIES"'                          "GBFC025868" 2004                .                 .                 . 1 . . 0
`""EMPEROR DIVERS" FOR DIVING ACTIVITIES"'                          "GBFC025868" 2005           300.92                 .          1524.374 0 . . 0
`""EMPEROR DIVERS" FOR DIVING ACTIVITIES"'                          "GBFC025868" 2006                .                 .                 . 0 . . 0
`""EMPEROR DIVERS" FOR DIVING ACTIVITIES"'                          "GBFC025868" 2007         1705.195                 .            39.468 0 . . 0
`""EMPEROR DIVERS" FOR DIVING ACTIVITIES"'                          "GBFC025868" 2008         1227.009                 .           -61.187 0 . . 0
`""EMPEROR DIVERS" FOR DIVING ACTIVITIES"'                          "GBFC025868" 2009          1849.93                 .            559.12 0 . . 0
`""EMPEROR DIVERS" FOR DIVING ACTIVITIES"'                          "GBFC025868" 2010                .                 .                 . 0 . . 0
`""EMPEROR DIVERS" FOR DIVING ACTIVITIES"'                          "GBFC025868" 2011                .                 .                 . 0 . . 0
`""EUROCERMEX""'                                                    "GBFC022489" 2004          445.185                 .          8864.687 1 . . 0
`""EUROCERMEX""'                                                    "GBFC022489" 2005              370                 .             10890 0 . . 0
`""EUROCERMEX""'                                                    "GBFC022489" 2006          292.461                 .         11291.073 0 . . 0
`""EUROCERMEX""'                                                    "GBFC022489" 2007          213.103                 .         14569.349 0 . . 0
`""EUROCERMEX""'                                                    "GBFC022489" 2008                .                 .                 . 0 . . 0
`""EUROCERMEX""'                                                    "GBFC022489" 2009                .                 .                 . 0 . . 0
`""EUROCERMEX""'                                                    "GBFC022489" 2010                .                 .                 . 0 . . 0
`""EUROCERMEX""'                                                    "GBFC022489" 2011                .                 .                 . 0 . . 0
`""FIVE TOWNS PLUS" HOSPICE FUND LIMITED(THE)"'                     "GB01797810" 2004          907.475                 .           347.376 1 . . 0
`""FIVE TOWNS PLUS" HOSPICE FUND LIMITED(THE)"'                     "GB01797810" 2005          883.357                 .           374.195 0 . . 0
`""FIVE TOWNS PLUS" HOSPICE FUND LIMITED(THE)"'                     "GB01797810" 2006          909.656                 .           376.938 0 . . 0
`""FIVE TOWNS PLUS" HOSPICE FUND LIMITED(THE)"'                     "GB01797810" 2007          863.007                 .           516.244 0 . . 0
`""FIVE TOWNS PLUS" HOSPICE FUND LIMITED(THE)"'                     "GB01797810" 2008         1097.131                 .           508.104 0 . . 0
`""FIVE TOWNS PLUS" HOSPICE FUND LIMITED(THE)"'                     "GB01797810" 2009         1237.631                 .            970.49 0 . . 0
`""FIVE TOWNS PLUS" HOSPICE FUND LIMITED(THE)"'                     "GB01797810" 2010         1190.228                 .           976.664 0 . . 0
`""FIVE TOWNS PLUS" HOSPICE FUND LIMITED(THE)"'                     "GB01797810" 2011         1148.862                 .          1033.386 0 . . 0
`""H.A.R.D.T." GROUP GMBH"'                                         "GBFC025624" 2004                .                 .                 . 1 . . 0
`""H.A.R.D.T." GROUP GMBH"'                                         "GBFC025624" 2005            78714                 .           1577286 0 . . 0
`""H.A.R.D.T." GROUP GMBH"'                                         "GBFC025624" 2006             5415                 .             -2941 0 . . 0
`""H.A.R.D.T." GROUP GMBH"'                                         "GBFC025624" 2007             6992             -1476              2802 0 . . 0
`""H.A.R.D.T." GROUP GMBH"'                                         "GBFC025624" 2008              233                 .              8531 0 . . 0
`""H.A.R.D.T." GROUP GMBH"'                                         "GBFC025624" 2009           107.86                 . 7411.904000000001 0 . . 0
`""H.A.R.D.T." GROUP GMBH"'                                         "GBFC025624" 2010                .                 .                 . 0 . . 0
`""H.A.R.D.T." GROUP GMBH"'                                         "GBFC025624" 2011                .                 .                 . 0 . . 0
`""IRISH MANAGEMENT INSTITUTE" (FORAS BAINISTIOCHTA NA H-EIREANN)"' "IE015151"   2004 21180.5141267313 -242.603031984669  332.873927606871 1 . . 0
`""IRISH MANAGEMENT INSTITUTE" (FORAS BAINISTIOCHTA NA H-EIREANN)"' "IE015151"   2005 24475.6719748685 -55.4941757862659  915.311343832732 0 . . 0
`""IRISH MANAGEMENT INSTITUTE" (FORAS BAINISTIOCHTA NA H-EIREANN)"' "IE015151"   2006 23688.9796432962 -.670354282735191  1385.62230241364 0 . . 0
`""IRISH MANAGEMENT INSTITUTE" (FORAS BAINISTIOCHTA NA H-EIREANN)"' "IE015151"   2007 25987.6661923845  -903.06901208586  784.031436855665 0 . . 0
`""IRISH MANAGEMENT INSTITUTE" (FORAS BAINISTIOCHTA NA H-EIREANN)"' "IE015151"   2008 33259.2971968488  -1083.5357593049 -1529.36060476339 0 . . 0
`""IRISH MANAGEMENT INSTITUTE" (FORAS BAINISTIOCHTA NA H-EIREANN)"' "IE015151"   2009 17991.7298228826 -2133.99386161848 -3391.79599597801 0 . . 0
`""IRISH MANAGEMENT INSTITUTE" (FORAS BAINISTIOCHTA NA H-EIREANN)"' "IE015151"   2010 15408.6142755874 -3744.30095747072 -5014.61250749558 0 . . 0
`""IRISH MANAGEMENT INSTITUTE" (FORAS BAINISTIOCHTA NA H-EIREANN)"' "IE015151"   2011 13306.3890040939  -4167.6614616596 -6191.23684605577 0 . . 0
`""K" LINE (EUROPE) LIMITED"'                                       "GB05639474" 2004                .                 .                 . 1 . . 0
`""K" LINE (EUROPE) LIMITED"'                                       "GB05639474" 2005                .                 .                 . 0 . . 0
`""K" LINE (EUROPE) LIMITED"'                                       "GB05639474" 2006             1143             -9127                67 0 . . 0
`""K" LINE (EUROPE) LIMITED"'                                       "GB05639474" 2007             1150             -7401               523 0 . . 0
`""K" LINE (EUROPE) LIMITED"'                                       "GB05639474" 2008         1226.314        -10714.279           400.992 0 . . 0
`""K" LINE (EUROPE) LIMITED"'                                       "GB05639474" 2009         1249.846         -11858.06           858.632 0 . . 0
`""K" LINE (EUROPE) LIMITED"'                                       "GB05639474" 2010          983.741        -10344.639          1626.294 0 . . 0
`""K" LINE (EUROPE) LIMITED"'                                       "GB05639474" 2011          831.549         -8843.738          2214.646 0 . . 0
`""K" LINE BULK SHIPPING (UK) LIMITED"'                             "GB04830352" 2004            23164             -9200             -9164 1 . . 0
`""K" LINE BULK SHIPPING (UK) LIMITED"'                             "GB04830352" 2005            45932             -2213              3239 0 . . 0
`""K" LINE BULK SHIPPING (UK) LIMITED"'                             "GB04830352" 2006            78816             -8059              -589 0 . . 0
`""K" LINE BULK SHIPPING (UK) LIMITED"'                             "GB04830352" 2007           102304             -4655              5557 0 . . 0
`""K" LINE BULK SHIPPING (UK) LIMITED"'                             "GB04830352" 2008       169611.363          -7370.48         53370.064 0 . . 0
`""K" LINE BULK SHIPPING (UK) LIMITED"'                             "GB04830352" 2009        225417.55        -12333.601         55603.483 0 . . 0
`""K" LINE BULK SHIPPING (UK) LIMITED"'                             "GB04830352" 2010       229556.869        -12020.425         68161.458 0 . . 0
`""K" LINE BULK SHIPPING (UK) LIMITED"'                             "GB04830352" 2011       323494.873         -18519.12         29097.656 0 . . 0
`""K" LINE HOLDING (EUROPE) LIMITED"'                               "GB05005018" 2004            26724            -14591             -7300 1 . . 0
`""K" LINE HOLDING (EUROPE) LIMITED"'                               "GB05005018" 2005        50299.194         -7615.321         14976.068 0 . . 0
`""K" LINE HOLDING (EUROPE) LIMITED"'                               "GB05005018" 2006            83680            -23335             32044 0 . . 0
`""K" LINE HOLDING (EUROPE) LIMITED"'                               "GB05005018" 2007           267177            -21885              -139 0 . . 0
end