1
$\begingroup$

I tried to find the estimate for SEM using R and Stata but I found that both estimates are different.

library(lavaan)
childfreq=as.numeric(data$bpfachildfreq)
childprob=as.numeric(data$bpfachildprob)
parentfreq=as.numeric(data$bpfaparentfreq)
parentprob=as.numeric(data$bpfaparentprob)
matrix=cbind(childfreq,childprob,parentfreq,parentprob)
cov=cov(matrix,use="pairwise.complete.obs",method="pearson")
n=nrow(data)
model<-'
FP =~ childfreq+childprob+parentfreq+parentprob
'
sem=sem(model,sample.cov=cov,sample.nobs =n)

Result from R:

enter image description here

sem(FP->bpfachildfreq bpfaparentfreq bpfachildprob bpfaparentprob), stand

Result from Stata:

enter image description here

Anyone knows how can I get the same result for both R and Stata? Thank you!

$\endgroup$

1 Answer 1

0
$\begingroup$

Do other things differ? Do the chi-square tests give the same value? Do you have any missing data, are you handling this differently? In R, you are using pairwise deletion - I don't think you're using that in Stata.

Can you check that your data are the same in both programs? In Stata, run

su

In R

summary(matrix)

You build the data in an unusual way.

What happens if you just run:

sem=sem(model, data)

It appe

Your variances seem very different, this can lead to precision problems. Multiply your variables by a constant.

You are asking for the standardized solution in Stata, not the regular (unstandardized) solution.

$\endgroup$
8
  • $\begingroup$ I have checked my data using summary and the data are same. I run my SEM model using lavaan package in R so my model need to be in following form: sem=sem(model,sample.cov=cov,sample.nobs =n). Yes, I asked for standardised solution in stata, I did ask for standardised solution in R as well. $\endgroup$
    – yap
    Commented Mar 22, 2020 at 6:38
  • $\begingroup$ Don't use pairwise deletion.Give Lavaan the data frame. $\endgroup$ Commented Mar 23, 2020 at 5:27
  • $\begingroup$ my data don't have missing data. I tried with complete.obs and I got the same result. I have also tried giving lavaan the data frame and I get the same results as sem=sem(model,sample.cov=cov,sample.nobs =n). Thank you! $\endgroup$
    – yap
    Commented Mar 23, 2020 at 7:39
  • $\begingroup$ You should not get the same results, because you analyzed a correlation matrix, not a covariance matrix. $\endgroup$ Commented Mar 23, 2020 at 16:18
  • $\begingroup$ do you mean STATA analyze using correlation? I used covariance matrix in R. $\endgroup$
    – yap
    Commented Mar 26, 2020 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.