Hello everyone,
I am new to stata and first time posting here so sorry and please do point out if I make a mistake with how I post or in ways I could make my codes more efficient.
In the code below, I manually have to enter the variable label and renaming and I tried to no avail to find a way to automate the process.
What I want to know is how can I use one variable content (IndicatorName) as a label for the new variable y and to rename y after the content of variable (IndicatorCode)
Both IndicatorName and Indicator code possess only one string that is repeated for each value of y - I just need them for the labeling and naming and then drop them before I integrate the updated version to master lists of variables. I have to do this for possibly hundreds of sheets so I am trying to automate as much as possible.
Thanks!
import excel "C:\Users\nadir\Downloads\wb_finsector\1", firstrow clear
drop E-AM CountryName BO
rename CountryCode ISO3
replace IndicatorCode = subinstr(IndicatorCode, ".","_",.)
rename (AN AO AP AQ AR AS AT AU AV AW AX AY AZ BA BB BC BD BE BF BG BH BI BJ BK BL BM BN)(y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019 y2020 y2021)
reshape long y, i(ISO3) j(year)
label variable y "International migrant stock, total"
rename y SM_POP_TOTL
drop IndicatorName IndicatorCode
save WB_FIN_O, replace
Comment