Hi all,
please consider the following data set:
input str3 ID byte str9 shock byte str1 evnt

ID shock evnt
1. 111 category1 y
2. 111 category2 y
3. 111 category3 n
4. 112 category1 y
5. 112 category2 n
6. 112 category3 n
7. end

. list

+------------------------+
| ID shock evnt |
|------------------------|
1. | 111 category1 y |
2. | 111 category2 y |
3. | 111 category3 n |
4. | 112 category1 y |
5. | 112 category2 n |
|------------------------|
6. | 112 category3 n |
+------------------------+
I am trying to create a new variable shock1 (occurence of shock of category1) for each ID, such that the data set looks like the following:
input str3 ID byte str1 shock1

ID shock1
1. 111 y
2. 112 y
3. end

. list

+--------------+
| ID shock1 |
|--------------|
1. | 111 y |
2. | 112 y |
+--------------+
I had started by trying to drop observations for which shock equals category2 and category3 but received error messages. Any help would be greatly appreciated.
Thank you.

Also, apologies for the tables not coming out as desired. I have installed dataex before generating the data set, but somehow the tables aren't coming out as they should.