Hello to everyone,
I want to generate a new variable that is the sum of the number of times another variable takes on a certain value. I can use the "count if" command, and I know that the value 351 appears 211 times in my ID variable. So I want to create a new column that will have the value 211 every time ID is equal to 351. And I know the value of 355 appears 494 times in my ID column, so I want my new variable column to have the value of 494 every time ID is equal to 355.
So if my data was the below, I would want it to look like this:
Since 355 appears 3 times, the newvar variable takes on the value of "3" everytime ID is equal to 355. And since 351 appears twice, newvar takes on the value of 2 every time ID is equal to 351. Unfortunately my is data large, with over 1,250 observations. Any assistance would be greatly appreciated.
I want to generate a new variable that is the sum of the number of times another variable takes on a certain value. I can use the "count if" command, and I know that the value 351 appears 211 times in my ID variable. So I want to create a new column that will have the value 211 every time ID is equal to 351. And I know the value of 355 appears 494 times in my ID column, so I want my new variable column to have the value of 494 every time ID is equal to 355.
So if my data was the below, I would want it to look like this:
ID: | newvar |
355 | 3 |
351 | 2 |
356 | 1 |
355 | 3 |
358 | 1 |
359 | 2 |
351 | 2 |
357 | 1 |
355 | 3 |
Comment