Dear Experts,
I need your assistance with a piece of code, where for some reason levelsof does not read a macro select2 in group 4, although it exists. I have lost it after 2 days of trying to get it right.
A .dta and .do Files are also being attached to this post.
Hope you can help me to get it right.
Sincerely,
Pavlo
I need your assistance with a piece of code, where for some reason levelsof does not read a macro select2 in group 4, although it exists. I have lost it after 2 days of trying to get it right.
A .dta and .do Files are also being attached to this post.
Hope you can help me to get it right.
Code:
su groups, meanonly
forvalues i = 1/`r(max)' {
foreach v in "Coating1_sub" "PumpStatus_sub" "EX_sub" {
egen tag`v' = tag(groups `v')
egen ndistinct`v' = total(tag`v'), by(groups)
replace `v' = . if ndistinct`v' < 2 /*set observations to missing if there are less that 2 groups in variable*/
drop tag`v' ndistinct`v'
capt confirm string var `v'
if ( _rc > 0 ) {
capture assert missing(`v') if groups == `i'
if ( _rc > 0 ) {
local varlist_`i' = "`varlist_`i''" + " " + "i.`v'"
local varlist_var`i' = "`varlist_var`i''" + " " + "`v'"
di "`varlist_`i''"
}
}
}
su obs if groups == `i', meanonly
local PumpName = new_PumpName[r(min)]
quietly: summarize Volume if groups == `i'
local m_min`i' = r(min)
local m_max`i' = r(max)
capture unab `varlist_var`i'' : ``var''
local variable_count = wordcount("`varlist_var`i''")
tokenize "`varlist_var`i''"
capture noisily reg log_GlobalPrice Volume `varlist_`i'' if groups == `i', robust baselevels
local select1 "`1'"
local select2 "`2'"
local select2 "`3'"
//extract coefficients of variables
forvalues k = 1/`variable_count' {
levelsof `select`k'' if e(sample), local(gcs)
foreach gc of local gcs {
replace `select`k''_var = _b[`gc'.`select`k''] if groups == `i' & `select`k'' == `gc'
}
}
}
Pavlo
Comment