# Estimate for structural equation model

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:

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

Result from Stata:

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

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.

• 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.
– yap
Commented Mar 22, 2020 at 6:38
• Don't use pairwise deletion.Give Lavaan the data frame. Commented Mar 23, 2020 at 5:27
• 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!
– yap
Commented Mar 23, 2020 at 7:39
• You should not get the same results, because you analyzed a correlation matrix, not a covariance matrix. Commented Mar 23, 2020 at 16:18
• do you mean STATA analyze using correlation? I used covariance matrix in R.
– yap
Commented Mar 26, 2020 at 9:44