Dear all,
I am hoping I can get some help with the following problem.
I have data for a number of companies (company_id) that compete in different markets. The variables market_A, market_B, market_C, and market_D take the value 1 if a company competes there and 0 otherwise. A sample of the data appears below.
I want to create a new variable for each market (competition_A, competition_B, competition_C, and competition_D) that takes values according to the following logic.
For example, for the variable competition_A for each company:
1) we consider whether a company operates in market A. If it doesn't, competition_A takes the value 0 for that company. This would be the case for company_id 1.
2) If a company operates in market A (such as company_id 2), we count the number of the markets it competes with each company in market A beyond market A. We take the sum of these calculations and divide it with the total number of companies in Market A that the company competes with (we divide with the number of companies it competes with in at least 1 market beyond market A).
Therefore:
- for company_id 2, competition_A would take the value 2 because: company_2 operates in market_A, and competes with company_id 3 in two other markets beyond market_A. As company_id 2 has no other competitors in market_A we divide 2 by 1.
- for company_id 3, competition_A would take the value 2 because: company_3 operates in market_A, and competes with company_id 2 in two other markets beyond market_A. As company_id 3 has no other competitors in market_A we divide 2 by 1.
The following dataset shows the result of the above calculations for all companies and markets.
Thank you for your time.
Pavlos
I am hoping I can get some help with the following problem.
I have data for a number of companies (company_id) that compete in different markets. The variables market_A, market_B, market_C, and market_D take the value 1 if a company competes there and 0 otherwise. A sample of the data appears below.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(company_id market_A market_B market_C market_D) 1 0 1 1 1 2 1 1 1 1 3 1 1 1 0 end
For example, for the variable competition_A for each company:
1) we consider whether a company operates in market A. If it doesn't, competition_A takes the value 0 for that company. This would be the case for company_id 1.
2) If a company operates in market A (such as company_id 2), we count the number of the markets it competes with each company in market A beyond market A. We take the sum of these calculations and divide it with the total number of companies in Market A that the company competes with (we divide with the number of companies it competes with in at least 1 market beyond market A).
Therefore:
- for company_id 2, competition_A would take the value 2 because: company_2 operates in market_A, and competes with company_id 3 in two other markets beyond market_A. As company_id 2 has no other competitors in market_A we divide 2 by 1.
- for company_id 3, competition_A would take the value 2 because: company_3 operates in market_A, and competes with company_id 2 in two other markets beyond market_A. As company_id 3 has no other competitors in market_A we divide 2 by 1.
The following dataset shows the result of the above calculations for all companies and markets.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(company_id market_A market_B market_C market_D competition_A competition_B competition_C competition_D) 1 0 1 1 1 0 2 1.5 2 2 1 1 1 1 2 2 2 2 3 1 1 1 0 2 1.5 1.5 0 end
Pavlos
Comment