I am looping 10 csv files (which are monthly data) and then trying to generate a month variable as a unique identifier. I tried to use the subinstr function to extract the month value from the file name but the function doesn't work. However, when I type "help subinstr" there is an explanation. Has stata changed the function name? How can I get around the issue. My code is below. X represents 01_2021, 02_2021, and so on all the way to 10_22. I am trying to extract the value "01,02, 03, etc. and make that the month value for the respective csv file.
This is the error I get:
subinstr not found
r(111);
HTML Code:
foreach x of local files { di "`x'" // Display file name *Import each filepath qui: import delimited "`x'", delimiter (",") case (lower) clear // Import csv file qui : gen id = subinstr ("`x'", "_2021.csv", "", .) // Generate id variable(same as file name but without _2021.csv) *Append each file to masterfile append using `dataset', force save `dataset', replace }
subinstr not found
r(111);
Comment