Hello,

I have a dataset recording all transaction at a market in a certain time period, including the quantity sold of a certain item per transaction. Also recorded is a unique customer ID for returning customers (‘cusn’) (1-258, with a lot of transactions where cusn is not specified). Now I need a new variable AVQUAN which gives the average quantity sold to that specific person in the entire time period. Thus, first I need to generate the sum of all quantitities sold per customer, and then average this over the number of occurrences of that ‘cusn’. Can anyone help with this? I've tried some options, but most require too much computing power.

The relevant available variables are:

‘cusn’ a customer number for each unique customer (1-258) (with a lot of missing values)

‘quan’ is the quantity sold to the customer in that particular transaction

As I see it; I first need to count the number of times a specific ‘cusn’ appears, then aggregate the total ‘quan’ over all these appearences, and then divide TOTALQUAN by the number of appearances. Can anyone help me with the quickest and most efficient code for this?

I am fairly new to stata, but eager to learn. Excuse me if it's too simple for this forum, or if I should clarify.

Thanks!

I have a dataset recording all transaction at a market in a certain time period, including the quantity sold of a certain item per transaction. Also recorded is a unique customer ID for returning customers (‘cusn’) (1-258, with a lot of transactions where cusn is not specified). Now I need a new variable AVQUAN which gives the average quantity sold to that specific person in the entire time period. Thus, first I need to generate the sum of all quantitities sold per customer, and then average this over the number of occurrences of that ‘cusn’. Can anyone help with this? I've tried some options, but most require too much computing power.

The relevant available variables are:

‘cusn’ a customer number for each unique customer (1-258) (with a lot of missing values)

‘quan’ is the quantity sold to the customer in that particular transaction

As I see it; I first need to count the number of times a specific ‘cusn’ appears, then aggregate the total ‘quan’ over all these appearences, and then divide TOTALQUAN by the number of appearances. Can anyone help me with the quickest and most efficient code for this?

I am fairly new to stata, but eager to learn. Excuse me if it's too simple for this forum, or if I should clarify.

Thanks!

## Comment