Hello everyone,
The problem I have is quite common. I would like to import a number of Excel files from different subfolders of a specific directory, but only those that pertain to a specific city. The issue is that the naming of the files is not consistent and I am unable to edit them. For example, in one folder, a city may be named "1234NewYork.xlsx" and in another "3112NY.xlsx" or "New_York.xlsx."
I am unable to find a systematic way to fix this without editing the files, and since I would like to loop my code over different cities, I believe I will have to use macros. I am wondering how I can define a set of possible keywords for each city in my folder and group them together in a way that Stata understands that a certain subset of these keywords belong to one city, so the files containing them should be appended.
Something like this:
local ny1 "New York"
local ny2 "New_York"
local ny3 "NY"
local ny4 "N_Y"
...
local la1 "Los Angeles"
local la2 "LA"
...
My goal is to have a number of appended files that corresponds to the number of cities. But I'm not really sure how I can make this work for each "group" of keywords. Please note that each city does not necessarily have the same number of files to be appended
Can someone help me? Any advice would be greatly appreciated!
The problem I have is quite common. I would like to import a number of Excel files from different subfolders of a specific directory, but only those that pertain to a specific city. The issue is that the naming of the files is not consistent and I am unable to edit them. For example, in one folder, a city may be named "1234NewYork.xlsx" and in another "3112NY.xlsx" or "New_York.xlsx."
I am unable to find a systematic way to fix this without editing the files, and since I would like to loop my code over different cities, I believe I will have to use macros. I am wondering how I can define a set of possible keywords for each city in my folder and group them together in a way that Stata understands that a certain subset of these keywords belong to one city, so the files containing them should be appended.
Something like this:
local ny1 "New York"
local ny2 "New_York"
local ny3 "NY"
local ny4 "N_Y"
...
local la1 "Los Angeles"
local la2 "LA"
...
My goal is to have a number of appended files that corresponds to the number of cities. But I'm not really sure how I can make this work for each "group" of keywords. Please note that each city does not necessarily have the same number of files to be appended
Can someone help me? Any advice would be greatly appreciated!
Comment