Dear Stata Community,
I am trying to use a global variable list definition in a collapse, but I have run into a problem. In my "main" do file I define a variable list (of all state-level variables, excluding the industry code and the year) as follows:
ds, has(type numeric)
local vars `r(varlist)'
local remove "year industry"
global my_state_vars: list vars - remove
di "`my_state_vars'"
later in the do file I call another do file in which the following commands appear:
foreach x of global my_state_vars {
replace `x' = 0 if `x' == .
}
collapse (sum) `my_state_vars', by(year region industry)
What puzzles me is that the loop, the replace, works fine, though the collapse returns a "varlist required".
This is my first attempt at using a global varlist, so I may be missing something simple. Thank you for your help,
Michael Anderson
I am trying to use a global variable list definition in a collapse, but I have run into a problem. In my "main" do file I define a variable list (of all state-level variables, excluding the industry code and the year) as follows:
ds, has(type numeric)
local vars `r(varlist)'
local remove "year industry"
global my_state_vars: list vars - remove
di "`my_state_vars'"
later in the do file I call another do file in which the following commands appear:
foreach x of global my_state_vars {
replace `x' = 0 if `x' == .
}
collapse (sum) `my_state_vars', by(year region industry)
What puzzles me is that the loop, the replace, works fine, though the collapse returns a "varlist required".
This is my first attempt at using a global varlist, so I may be missing something simple. Thank you for your help,
Michael Anderson
Comment