I'm working on my first Stata project and I have around 30 huge datasets with hundreds of variables. I want a loop that goes through each of them, keeps only the variables I am interested in and saves the reduced form data sets somewhere else. Other solutions didn't work for me 1. because many other people want to overwrite their original sources: for me it is crucial that the original data set remains unmodified and I get the output saved somewhere else to work with. 2. I guess I made a syntax mistake, because I'm relatively new.
Here's what I've produced so far
cd Y:\MAIA\Data\Data2014\
foreach file{
keep nopnltNF NumMois ptwa Qu cvwp ctwpenwp
sort nopnltNF NumMois
save `file'.dta in Y:\MAIA\MyName\test_folder}
Resulting in the error invalid syntax r(198);
foreach filedoesn't fit any of the allowed syntax patterns. There is always aninor anofas keyword. Beyond that, did you read in any data before doing this?use wdNote thesavecommand is wrong.