Dear all,
I use the TNIC data from Hoberg&Phillips and want to sort the scores pro competitor_rank1 in descending order in order to keep only the top 5 competitors for each gvkey1. I am not experienced with STATA and tried to do it using the following code, but the score is still in descending order:
clear
cd "C:\Users\etc"
use tnic3
sort gvkey1 score
gen competitor_rank = _n
sort competitor_rank gvkey1
egen competitor_rank1 = group(gvkey1)
bysort competitor_rank1 (score): gen descending_order = _n
sort competitor_rank1 -descending_order
alternative:
use tnic3
sort gvkey1 score
gen competitor_rank= _n
sort competitor_rank gvkey1
egen competitor_rank1=group(gvkey1)
sort -score competitor_rank1
(here the error is "- invalid name" even if the column is names "score")
Any help, however small would be greatly appreciated! Thank you in advance!
Related Posts with Order data in descending order
Odd Stata/Mata bug when using xtreg, fe in a program together with Mata views under version controlUnder Stata 15.1, I experienced an odd behavior in a program that I have written. I first created a …
Generate vars with conditions inside a loopHi, I have a question, why the next sintaxis(with conditions) is not possible? foreach i of numlis…
How to Calculating time difference between visits in a panel dataI hope this finds you well. I kindly need your help to calculate the time difference(Months, Years …
CTRL+F in browse mode not working properlyHi all, I am using a dataset with Greek characters. I've noticed that when I do a ctrl+f in browse …
displaying 14-digit numeric variable (double) in tab and codebook commandsHello, I have a 14-digit numeric variable, named 'year_id' (type double), which I would like STATA …
Subscribe to:
Post Comments (Atom)
0 Response to Order data in descending order
Post a Comment