There are several panel datasets I'd like to join.
The observations in these datasets are identified by an id variable and a variable identifying the time the observation was made. All datasets include some variables I need, some I don't need and never the same variables (excluding the id and the survey-time-variable).
The datasets are huge, so to speed up processing and decrease the size of the final dataset, I want to drop
all variables I don't need.
Thoose variables are stored in an Excel file with several columns. One of these columns, say, C2, contains all my variable names.
Now I believe I have two possible ways to follow, which I describe in order of my favour:
1) Read in the variable-names from the Excel file into a global in Stata and then state:
keep global varlist
That way only variables I need should be retained.
2) Generate a new empty dataset with all the variables from the Excel file and then
joinby id syear $varlist using dataset, update
Anyhow I need to read out the variables from the excel file into a global. I realize that I could do this by just copy and paste from Excel into Stata, but I suppose there will be some changes in the variables as I go along with the work and I want to learn how to program properly in Stata.
I would recommend reading the variable names into a
local
, and use onlyglobal
if strictly necessary.One way to do that is to use
import excel
along withlevelsof
:The MS Excel file reads
in the corresponding cells.
The result :
See also
help file read
, but for your case, it seems an unnecessarily complicated path.