Hi all,
I am using Stata/SE 12.1.
I have data that looks like the example below. Suppose there are three firms in a market who change their prices for a certain product frequently.
For each observation (firm-date combination), I want to compute the minimum price in the market and save this price in a variable (called min_price).
The entries should look like min_price_shouldbe.
Unfortunately, I don't know how to get there. More precisely, I don't know how to translate the following conditions into Stata code:
1) Only look at price changes with date < date[_n]
2) Only consider the last price change (with date < date_[n]) of each competitor
Any ideas?
Best,
Christoph
I am using Stata/SE 12.1.
I have data that looks like the example below. Suppose there are three firms in a market who change their prices for a certain product frequently.
For each observation (firm-date combination), I want to compute the minimum price in the market and save this price in a variable (called min_price).
The entries should look like min_price_shouldbe.
Unfortunately, I don't know how to get there. More precisely, I don't know how to translate the following conditions into Stata code:
1) Only look at price changes with date < date[_n]
2) Only consider the last price change (with date < date_[n]) of each competitor
Any ideas?
Best,
Christoph
Code:
clear input id price_change str16 date_help min_price min_price_shouldbe 1 109 "21dec2014" . 108 1 105 "25jan2015" . 100 1 113 "26feb2015" . 58 2 108 "15dec2014" . 108 2 156 "01feb2015" . 100 2 58 "20feb2015" . 58 3 455 "01jan2015" . 108 3 100 "15jan2015" . 100 3 390 "16feb2015" . 105 end gen date = date(date_help,"DMY") format date %td sort date
Comment