Array

Above is a picture of a subset of my data. hs10 refers to a specific product being sold and m_val is a value the product takes on. What I need to do is generaet a variable that is the log difference of m_val for period 1 and 2. The problem however is that there are a number of products that don't have m_val for both periods. For those products, I want the generated value to simply be the log of m_val.

I am lost with where to start!