Dear all,
I am using Stata 14.
I would like to calculate the average (mean of the variable "decision") of a specific group (here it is defined as beeing in a specific market "market_id") per frim ("retailer"), thereby excluding the firm itself. My code looks as follows
This gives me the average of all firms in a given market per year. Hoiwever, I only want the average of the competitors thereby excluding firm i itself, when calculating the average by firm and group.
I hope my question is clear.
Best
Markus
I am using Stata 14.
I would like to calculate the average (mean of the variable "decision") of a specific group (here it is defined as beeing in a specific market "market_id") per frim ("retailer"), thereby excluding the firm itself. My code looks as follows
clear
input str2 retailer byte(market_id retailer_id year decision)
"CO" 10 1 11 1
"CO" 10 1 12 1
"CO" 10 1 13 1
"DL" 10 2 11 1
"DL" 10 2 12 0
"DL" 10 2 13 0
"DL" 10 2 14 0
"DL" 10 2 15 1
"EV" 5 3 11 1
"EV" 5 3 12 0
"EV" 5 3 13 0
"NW" 5 4 11 0
"NW" 5 4 12 0
"NW" 5 4 13 0
"NW" 5 4 14 0
"GY" 10 5 11 0
"GY" 10 5 12 0
"GY" 10 4 13 1
end
sort market_id year
by market_id year: egen peer_decision = mean(decision)
input str2 retailer byte(market_id retailer_id year decision)
"CO" 10 1 11 1
"CO" 10 1 12 1
"CO" 10 1 13 1
"DL" 10 2 11 1
"DL" 10 2 12 0
"DL" 10 2 13 0
"DL" 10 2 14 0
"DL" 10 2 15 1
"EV" 5 3 11 1
"EV" 5 3 12 0
"EV" 5 3 13 0
"NW" 5 4 11 0
"NW" 5 4 12 0
"NW" 5 4 13 0
"NW" 5 4 14 0
"GY" 10 5 11 0
"GY" 10 5 12 0
"GY" 10 4 13 1
end
sort market_id year
by market_id year: egen peer_decision = mean(decision)
Example:
CO is on the same market as DL and GY. Thus I want the average of the decision of DL and GY (by year). Yet, by market_id year: egen peer_decision = mean(decision) inludes CO itself.
I could of course drop CO calculate the value and merge again. Yet, as I have many retailers this might soon become very messi.
CO is on the same market as DL and GY. Thus I want the average of the decision of DL and GY (by year). Yet, by market_id year: egen peer_decision = mean(decision) inludes CO itself.
I could of course drop CO calculate the value and merge again. Yet, as I have many retailers this might soon become very messi.
Best
Markus
Comment