Hello everyone,

I have one question related to counting distinct values by groups. Here is an example of the data with ID, year, and the job code (i.e., job_code). What I am looking for is to create a variable (or collapse data) that shows how many jobs they have throughout the year from 1994 to 1996. For example, ID 1 had 3 jobs, ID 2 had 1 and ID 3 had 3.

Code:
input ID year job_code
1 1994 50
1 1995 53
1 1996 60
2 1994 35
3 1994 68
3 1995 60
3 1996 53
end
I am aware of the command -distinct- :
Code:
bysort ID: distinct job_code
but of course, it only lists out the number of distinct values for each ID. I do not know how to incorporate the -distinct- command with other commands to create a new variable that can show me how many jobs each ID has.

Could anyone help me with this question, please? Thank you in advance, and stay safe.