Hi all,

please consider the following table for my question. The first two variables are given in my data set and I would like to add the third column in my data set. The numbers of the variables C are determined as follows: Variable C is a counter for the number of observations of variable B for a given variable A.

This means that:

- Variable C is always a 1 for every first entry of a new ID of variable A

- If an ID exists multiple times in variable A, then variable C is a counter for the number of observations of variable B

I hope the table makes it clear, what I am trying to do. Does anyone know how to set this up in Stata? I only know how to do this in Excel and am currently struggling to do the same in Stata.

Thank you for your help!

please consider the following table for my question. The first two variables are given in my data set and I would like to add the third column in my data set. The numbers of the variables C are determined as follows: Variable C is a counter for the number of observations of variable B for a given variable A.

This means that:

- Variable C is always a 1 for every first entry of a new ID of variable A

- If an ID exists multiple times in variable A, then variable C is a counter for the number of observations of variable B

I hope the table makes it clear, what I am trying to do. Does anyone know how to set this up in Stata? I only know how to do this in Excel and am currently struggling to do the same in Stata.

A | B | C |

1 | Tom | 1 |

1 | Tom | 2 |

1 | Martin | 1 |

1 | Tom | 3 |

1 | Chris | 1 |

1 | Martin | 2 |

1 | Tom | 4 |

2 | Tom | 1 |

2 | Sophie | 1 |

2 | Tom | 2 |

3 | Martin | 1 |

4 | Tom | 1 |

4 | Tom | 2 |

5 | Tom | 1 |

5 | Martin | 1 |

5 | Martin | 2 |

5 | Martin | 3 |

## Comment