Dear Statalist,
I have data on each JEL codes (KW_A, KW,B, ...) declared by each individual (ref). I would like to create a new variable named max_kw which is the variable name of the maximum JEL code.
More specifically, I would like that the variable
max_kw = KW_A if for an individual ref KW_A is the max of (KW_A KW_B KW_C KW_D KW_E KW_F KW_G KW_H KW_I KW_J KW_K KW_L KW_M KW_N KW_O KW_P KW_Q KW_R KW_T KW_Y KW_Z)
I have tried to implement a code provided by Nick Cox in the forum last year; but I get no results.
My code is the following:
unab xvars: KW_A KW_B KW_C KW_D KW_E KW_F KW_G KW_H KW_I KW_J KW_K KW_L KW_M KW_N KW_O KW_P KW_Q KW_R KW_T KW_Y KW_Z
gen max_kw = ""
gen max = 0
quietly foreach x of local xvars {
replace max_kw = "`x'" if `x' > `max'
replace max = `x' if `x' > `max'
}
I get an "invalid syntax" error message.
Could someone help me to fix the code.
Thanks in advance
Francisco
NB: I do not want to do the code in long format
I have data on each JEL codes (KW_A, KW,B, ...) declared by each individual (ref). I would like to create a new variable named max_kw which is the variable name of the maximum JEL code.
More specifically, I would like that the variable
max_kw = KW_A if for an individual ref KW_A is the max of (KW_A KW_B KW_C KW_D KW_E KW_F KW_G KW_H KW_I KW_J KW_K KW_L KW_M KW_N KW_O KW_P KW_Q KW_R KW_T KW_Y KW_Z)
I have tried to implement a code provided by Nick Cox in the forum last year; but I get no results.
My code is the following:
unab xvars: KW_A KW_B KW_C KW_D KW_E KW_F KW_G KW_H KW_I KW_J KW_K KW_L KW_M KW_N KW_O KW_P KW_Q KW_R KW_T KW_Y KW_Z
gen max_kw = ""
gen max = 0
quietly foreach x of local xvars {
replace max_kw = "`x'" if `x' > `max'
replace max = `x' if `x' > `max'
}
I get an "invalid syntax" error message.
Could someone help me to fix the code.
Thanks in advance
Francisco
NB: I do not want to do the code in long format
Comment