Hi all,
The panel data I have is to analyse firms' problems. Now, the following table shows the basic information I am going to use.
Basically, if the selling prices are at least or higher than $5, it is considered as the high-priced products; otherwise is low-priced products.

Here, the data records the selling information of all firms within two years. Another default setting is that "month" is a string variable currently.

I would like to calculate the average monthly high/low prices based on firms' code without missing data.
year month firm_code selling prices high price low price average high prices average low prices desired average high prices desired average low prices
2016 mar A 6.7 6.7 . 6.7 3 6.7 3
2016 mar A 3 . 3 6.7 3 6.7 3
2016 mar T 2 . 2 . 2 x1 2
2016 apr W 2.3 . 2.3 5.1 2.3 5.1 2.3
2016 apr T 3.5 . 3.5 . 3.5 x1 3.5
2016 apr W 5.1 5.1 . 5.1 2.3 5.1 2.3
2017 mar W 2.3 . 2.3 . 2.35 z1 2.35
2017 mar T 9 9 . 9 . 9 z2
2017 mar A 7.8 7.8 . 7.8 . 7.8 z3
2017 mar W 2.4 . 2.4 . 2.35 z1 2.35
2017 apr A 5 5 . 5 . 5 z3
2017 apr W 1 7 . 7 . 7 2.35
Notes: Assume "x~" refers to the value derived from last month, Feb 2016; "z~" is the value derived from Feb 2017. The unknown values 'x~' or 'z~' did provide in the data but are not being shown here.

May I know how do I get that?

Don't hesitate to comment if any unclear. Thanks in advance.