HI all,

Please consider the following data set: data set_1

clear

. input str8 respid byte str5 commid

respid commid
1. XY050037 XY001
2. XY050038 XY001
3. XY050050 XY002
4. XY050014 XY003
5. end

. list

+-------------------+
| respid commid |
|-------------------|
1. | XY050037 XY001 |
2. | XY050038 XY001 |
3. | XY050050 XY002 |
4. | XY050014 XY003 |
+-------------------+

. clear

Now i have another data set, on the same observations, but without the commid. For eg: Data set_2:

input str5 respid

respid
1. 50037
2. 50038
3. 50050
4. 50014
5. end

. list

+--------+
| respid |
|--------|
1. | 50037 |
2. | 50038 |
3. | 50050 |
4. | 50014 |
+--------+
I'm trying to generate commid for the observations in Dataset_2, just like in Dataset_1. For instance, the respid-50037 in dataset_2 is XY50037 in dataset_1 and would like to introduce a commid- XY001 in dataset_2 corresponding to it.

I have been looking at posts about using loops for generating ID variables but am unable to find a solution to my problem. Would greatly appreciate your help.
Thank you.