Hi everyone,

I am looking for a way to convert a dataset from the long format to a wide format. However, I only have time as a continuous variable in weeks at multiple dp.
I can't figure out how to assign a visit variable via a code. I mean I can do it manually, but there's I have a large N.
Below is an example of 10 observations from the dataset:

id week age sex
1 0 36.4271 Male
1 7.5714 36.4271 Male
1 15.5714 36.4271 Male
1 23.5714 36.4271 Male
1 32.5714 36.4271 Male
1 40 36.4271 Male
2 0 47.8467 Male
2 8 47.8467 Male
2 16 47.8467 Male
2 23 47.8467 Male
2 30.7143 47.8467 Male
2 39 47.8467 Male
3 0 60.2875 Male
4 0 36.5969 Male
4 7.1429 36.5969 Male
4 16.1429 36.5969 Male
4 32.4286 36.5969 Male
5 0 35.948 Male
5 8 35.948 Male
5 16 35.948 Male
5 24 35.948 Male
5 32 35.948 Male
5 40 35.948 Male

Any help or guidance will be much appreciated. I am using stata v17.