I have two datasets and want to keep only some variables (columns) in one dataset that are found as rows in another dataset. For example,
The dataset temp1 currently has 7 variables (columns), but I only want to keep the 3 variables listed in variable_name of the temp2 dataset. My actual problem is much larger, need to keep/drop 1000s of variables, else I could just do it by hand. (You can disregard the age variable in the temp2 dataset as well as the variable values in temp1 dataset.)
The resulting dataset should look like this:
Thanks in advance.
Code:
clear input a_a b_b c_c d_d e_e f_f g_g 1 2 3 4 5 6 7 end save temp1, replace clear input str16 variable_name age "a_a" 22 "c_c" 26 "g_g" 29 end save temp2, replace
The dataset temp1 currently has 7 variables (columns), but I only want to keep the 3 variables listed in variable_name of the temp2 dataset. My actual problem is much larger, need to keep/drop 1000s of variables, else I could just do it by hand. (You can disregard the age variable in the temp2 dataset as well as the variable values in temp1 dataset.)
The resulting dataset should look like this:
Code:
clear input a_a c_c g_g 1 3 7 end save temp3, replace
Comment