Adding rows in a variable to equal the number of observations with another variable

To be able to help you further, I think we need a reproducible example. That is, a data sample plus the code you've tried and error(s) you're getting. For more on providing a reproducible example, see here.