0
votes

I have a series of transactions that each indicate how much units were purchased. For example, I have

  • Bud Light 3 units 30 cents per ounce
  • Miller Light 2 units 23 cents per ounce

I want to duplicate Bud Light 3 times and Miller Light 2 times:

  • Bud Light 1 unit 30 cents per ounce
  • Bud Light 1 unit 30 cents per ounce
  • Bud Light 1 unit 30 cents per ounce
  • Miller Light 1 unit 23 cents per ounce
  • Miller Light 1 unit 23 cents per ounce

In other words, I need to create as many single purchase entries as how many purchases were made as indicated in one of my columns.

How can I do that? Appreciate any input.

1
This question seems off-topic for this site. Please read stackoverflow.com/help/on-topic. help expand should solve your problem.Roberto Ferrer
Agreed that this is not appropriate for SO. Ask further questions on Statalist.Steve Samuels
This tremendously helped. Thank you so much!Olga

1 Answers

1
votes

There is a command that does exactly that.

Look at expand

Description

expand replaces each observation in the dataset with n copies of the observation, where n is equal to the
required expression rounded to the nearest integer.  If the expression is less than 1 or equal to missing,
it is interpreted as if it were 1, and the observation is retained but not duplicated.