Hello everyone!
I have a dataset based on individual observations for each respondent of a questionnaire (only for one year). Because the subsequent datasets for other years do not follow individuals on time and there is no individual id, I want to create means of the values of the variable of interest (p32xx) by province (ccaa).
When I create the variable using: egen ca30=mean( p32xx), by(ccaa) I see a variable with the number of values just as the number of provinces, but I don't have the name of the provinces with the respective mean value as the frequency for each one, instead I have the mean as the label of each value, and the number of observations as the frequency. So I would like to have a variable with the name of the provinces (ccaa), and the mean value for p32xx within provinces (ccaa).
Hope you can help me, thanks!
I have a dataset based on individual observations for each respondent of a questionnaire (only for one year). Because the subsequent datasets for other years do not follow individuals on time and there is no individual id, I want to create means of the values of the variable of interest (p32xx) by province (ccaa).
When I create the variable using: egen ca30=mean( p32xx), by(ccaa) I see a variable with the number of values just as the number of provinces, but I don't have the name of the provinces with the respective mean value as the frequency for each one, instead I have the mean as the label of each value, and the number of observations as the frequency. So I would like to have a variable with the name of the provinces (ccaa), and the mean value for p32xx within provinces (ccaa).
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float ca30 double(ccaa p32xx) 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 6 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 6 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 6 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 6 2.0045533 2 1 2.0045533 2 6 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 6 2.0045533 2 6 2.0045533 2 1 2.0045533 2 6 2.0045533 2 6 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 6 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 6 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 6 2.0045533 2 6 2.0045533 2 1 2.0045533 2 1 2.0045533 2 6 2.0045533 2 1 2.0045533 2 6 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 6 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 1 2.0045533 2 6 end label values ccaa ccaa label def ccaa 2 "Arag�n", modify label values p32xx p32xx label def p32xx 1 "S�", modify label def p32xx 6 "No", modify
Hope you can help me, thanks!
Comment