Merging observations which occur at the same time into one observation

Viewed 30

I have a dataset which looks like this:

loan  client  time      interest   loan amount   country    
1       1      w          0.1       500.000        USA            
2       1      x          0.2       250.000        Germany               
3       2      y          0.1       300.000        France                 
4       2      y          0.15      400.000        France                
5       2      y          0.2       100.000        France            
6       3      z          0.1        50.000        England            
.       .      .           .           .               .
.       .      .           .           .               .

I observe different clients at different point in times. For some observations I observe the same client at the same time receiving 2 different loans (in this example observing client 2 at time y 3 times). I want to bundle these observations together meaning that I want to replace loans "3", "4" & "5" with one observation "3", summing the loan amount, averaging the interest rate and using the entries for all other variables from observation "3". I am wondering how I can perform these operations using Stata.

1 Answers

This ended up working for me:

collapse (mean) interest (sum) loanamount (firstnm) country, by (client time) 

Related