Please, could anyone help with the correct command?
I have two datasets measuring the weight of a product using two different methods. I want to know the correlation between this two variables called 'grams1' and 'grams2'.
The two data sets have the same id variable, the same time var and the grams var differ between both data. The two data sets samples and my codes are below. Is this the correct way to assess the correlation between this two variables? What I expect is that the correlation is very high indicating that both weighting methods are similar and yield close weight in grams.
Thank you!
Grams1.dta
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id grams1 time) 11 13 1 11 12 2 11 19 3 22 21 1 22 10 2 22 15 3 33 35 1 33 29 2 33 20 3 end
Grams2.dta
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id grams2 time) 11 21 1 11 12 2 11 18 3 22 21.5 1 22 11 2 22 14.7 3 33 36 1 33 29 2 33 20.6 3 end
I then tried to do the following:
Code:
use grams1,clear sort id time merge 1:1 id time using grams2
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id grams1 time grams2) byte _merge 11 13 1 21 3 11 12 2 12 3 11 19 3 18 3 22 21 1 21.5 3 22 10 2 11 3 22 15 3 14.7 3 33 35 1 36 3 33 29 2 29 3 33 20 3 20.6 3 end label values _merge _merge label def _merge 3 "matched (3)", modify
Code:
pwcorr grams1 grams2, star(0.01)
0 Response to Correlation between variables
Post a Comment