Hi
Please, I want to create a string variable that picks up the value "EN" from the string variable location_ncreif (as shown in the example) as this is the value with the highest frequency
i would normally do the following
bysort snl_instn_key year location_ncreif : gen ttl_no_location_ncreif = _N
bysort snl_instn_key year : egen max_no = max(ttl_no_location_ncreif)
bysort snl_instn_key year : gen newvar = location_ncreif if max_no == ttl_no_location_ncreif
(as shown in the second example)
but that would leave the last 2 observations without the value "EN" because, of course, they don't match the condition
so please, how can i create a variable with the value "EN" for the whole year
and is there a command where i can directly generate a variable that picks up the string value with the highest frequency?
Thank you in advance.
Please, I want to create a string variable that picks up the value "EN" from the string variable location_ncreif (as shown in the example) as this is the value with the highest frequency
i would normally do the following
bysort snl_instn_key year location_ncreif : gen ttl_no_location_ncreif = _N
bysort snl_instn_key year : egen max_no = max(ttl_no_location_ncreif)
bysort snl_instn_key year : gen newvar = location_ncreif if max_no == ttl_no_location_ncreif
(as shown in the second example)
but that would leave the last 2 observations without the value "EN" because, of course, they don't match the condition
so please, how can i create a variable with the value "EN" for the whole year
and is there a command where i can directly generate a variable that picks up the string value with the highest frequency?
Thank you in advance.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str9 snl_instn_key float year str9 location_ncreif "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "EN" "102910" 2002 "SE" "102910" 2002 "unkncreif" end
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str9 snl_instn_key float year str9 location_ncreif float(ttl_no_location_ncreif max_no) str9 ncreif_FE_no "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "EN" 19 19 "EN" "102910" 2002 "SE" 1 19 "" "102910" 2002 "unkncreif" 1 19 "" end

Comment