Hello,

My data has the following variables: symbol (to identify which firm it is), year, industry and mandatory (a dummy variable =1 if the firm is "mandatory"). I want to compute the proportion of firms that are "mandatory" by a given industry and a given year excluding the focal firm. After reading https://www.statalist.org/forums/for...ding-own-value and https://www.statalist.org/forums/for...interval-t-1-0, I wrote the following:

Code:
sort Year industry Symbol
rangestat (mean) mandatory_prop=mandatory, interval(Year 0 0) by(industry) excludeself
I'd appreciate it if you could let me know if my code looks reasonable. I have a further question, it may be obvious but I really don't know (my apologies), how can I kind of "extract" the value of mandatory_prop when mandatory=1 to make it a new variable, as that I can use it as a variable in the regression.

Thanks!