Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65570

Panel data: Ranking entities by average of a variable

$
0
0
Hi Stata folks,

I have an unbalanced panel data of firms i at time t. I have a variable, say x for every firm at every point in time. I took the average of x for every firm over time in the following manner:
Code:
  bysort firm_id (year): egen avgx = mean(x)
Now I want to rank the firms using this average variable within every industry s. The way I know to do this would be:
Code:
  by firm_id: keep if year == year [1]
  bysort industry_id (firm_id): egen rankx = rank(avgx)
The first line will keep every firm only once. If I don't do this, I will not get the correct ranks when using avgx.

My problem is that I don't want to drop all these observations in order rank the firms because I will need them for my other variables that I am not averaging. How do I go about this problem?
Note: I only have two dimensions: firm and time. I use industries only to rank the firms properly because they are not comparable otherwise. I would like to have the rank variable for each firm be the same across all time points just like the avgx variable.

I hope my explanation makes sense.


Viewing all articles
Browse latest Browse all 65570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>