I am very new to macros and looping (in Stata). I have certain variables for which it is necessary to have non-missing values to include them in regression. I used the following code to drop those observations with missing values of the assigned variables (under essentials), but it says it is an invalid syntax. Am I doing something wrong?
Code:
local essentials resp_edu_2014 resp_edu_2016 haschild_2014 haschild_2016 eqk2_2016 inc_asp_2014 inc_asp_2016 ast_asp_2014 ast_asp_2016 edu_asp_2014 edu_asp_2016 stat_asp_2014 stat_asp_2016 ln_oil_2014 ln_oil_2016 ln_sugar_2014 ln_sugar_2016 ln_salt_2014 ln_salt_2016 foreach var in `essentials' { drop if missing(`var') }
Code:
local essentials resp_edu_2014 resp_edu_2016 haschild_2014 haschild_2016 eqk2_2016 inc_asp_2014 inc_asp_2016 ast_asp_2014 ast_asp_2016 edu_asp_2014 edu_asp_2016 stat_asp_2014 stat_asp_2016 ln_oil_2014 ln_oil_2016 ln_sugar_2014 ln_sugar_2016 ln_salt_2014 ln_salt_2016 foreach var in `essentials' { drop if `var'==. }
Thanks!
0 Response to Deleting observations with missing values using macro/looping
Post a Comment