Hello everyone,
I am currently working on a data set that has both a year variable along with pertinent IV and DV variables. Since I want to make suggestions about causality, this means that I need to transform some of my variables by year. I have done so, however, now I'm not sure if I did so correctly.

In this regard, I am needing to run SEM- but when I do so, I get a 'no observations found' error. I suspect it has something to do with my coding and utilization of the year variable.
Is there some other code I can use, such as doing sem with an if command? I have not done this before so wondering if there are alternatives.

Here is my code for what I have done as an example:

*make carsi for 2011
gen carsi_2011=.
replace carsi_2011=0 if carsi==0 & year==2011
replace carsi_2011=1 if carsi==1 & year==2011
label values carsi_2011 label_carsi
sort country
by country: tab carsi_2011 year, miss

*MAKE FOR >=2012
gen disorg9_2012=.
replace disorg9_2012=0 if disorg9==0 & year>=2012
replace disorg9_2012=1 if disorg9==1 & year>=2012
replace disorg9_2012=2 if disorg9==2 & year>=2012
replace disorg9_2012=3 if disorg9==3 & year>=2012
replace disorg9_2012=4 if disorg9==4 & year>=2012
tab disorg9_2012 disorg9, miss
tab disorg9_2012 year, miss
tab disorg9_2012 country, miss

*>=2012
gen soco1_2012=.
replace soco1_2012=0 if mysoco1==0 & year>=2012
replace soco1_2012=1 if mysoco1==1 & year>=2012
replace soco1_2012=2 if mysoco1==2 & year>=2012
replace soco1_2012=3 if mysoco1==3 & year>=2012
tab soco1_2012 country, miss
tab soco1_2012 year, miss
label values soco1_2012 label_soco

sem (CE -> soco1_2012) (CE -> soco2_2012) (CE -> soco3_2012) (Disorg -> disorg9_2012) (Disorg -> disorg10_2012) (Disorg -> disorg15_2012) (Disorg -> disorg17_2012) (Disorg -> disorg18_2012) (carsi_2011 -> CE) (carsi_2011 -> Disorg)