Anyone knows how to translate this stata command into a R command?
by city, sort : egen float total_population = total (id)
Example
id city
1 a
1 a
1 a
2 r
2 r
3 r
6 h
7 h
8 h
9 h
10 h
Expected result
id city total _population
1 a 1
1 a 1
1 a 1
2 r 2
2 r 2
3 r 2
6 h 5
7 h 5
8 h 5
9 h 5
10 h 5