Page 1 of 1
Run social relations model macro using runmlwin
Posted: Fri Oct 11, 2013 9:45 am
by kurt0509
Dear all,
I am trying to run social relations model. I wonder if there's a way I can directly run MLwin Macro within the STATA. If not, is there any runmlwin command that I can run this social relations model within STATA? I am more familiar with STATA and somehow MLwin is not properly working with the macro. The macro is from Tom Snijder
http://www.stats.ox.ac.uk/~snijders/srm.htm. I would appreciate your advice.
Re: Run social relations model macro using runmlwin
Posted: Fri Oct 11, 2013 9:59 am
by ChrisCharlton
Would it be possible to provide a link to the version of the macro that you are using, as the links on the page you referenced don't appear to be working currently?
Re: Run social relations model macro using runmlwin
Posted: Fri Oct 11, 2013 10:27 am
by kurt0509
Below is the MLwiN macro.
echo 1
Note Actors, partners, dependent variable, are in columns with numbers
print B11-B13
Note The number of covariates is
print B10
Note The group identifier is in column number
print B15
echo 0
Note First the dyad identifier (to specify the nesting structure)
Note is calculated.
clear
max CB12 CB13 C121
min CB12 CB13 C122
calc C123 = C121 + B14*C122
calc C124 = 1.5 + 0.5*sign(CB12-CB13)
calc C125 = C124 + 2*C123
calc B20 = sign(B10)
switch B20
CASE -1:
say \n The number of covariates is negative.
say \n This is an error, because the number of covariates must be nonnegative.
say \n The macro stops here. \n
abort
LEAVE
CASE 0:
sort 2 CB15 C125 CB11 CB12 CB13 C123 C124 C129-C135
Note There are no covariates (since B10 = 0).
LEAVE
CASE 1:
calc B7 = 300 + B10
sort 2 CB15 C125 CB11 CB12 CB13 C123 C124 CB8-CB9 C129-C135 C301-CB7
echo 1
Note Covariates are assumed to be in the columns starting
print B8
Note and ending with
print B9
Note They are now represented by the columns numbered from 301 to
print B7
echo 0
endswitch
calc C136 = 0*C130 + 1
name C136 'const'
calc C137 = C136
name C137 'conss'
Note Now the dependent variable is in C131,
Note the actor in C132, the partner in C133,
Note the group identifier in C129,
Note the covariates in C301-CB7.
Note definition of the nesting structure:
name C135 'obs' C134 'dyad'
iden 1 'obs'
iden 2 'dyad'
iden 3 C129
aver C129 B22 B23 B24
calc B22 = sign(B24)
Note B24 is the standard deviation of the group identifier,
Note so B22 = 0 if there is one group and B22 = 1 if there are more groups.
switch B22
CASE 0:
echo 1
Note There is a single group.
Note The number of individuals is given as
print B14
echo 0
LEAVE
CASE 1:
echo 1
Note There are multiple groups.
Note The maximum number of individuals is given as
print B14
echo 0
endswitch
Note In the notation of S&B, C135='obs' is i [with values 1 and 2]
Note and c134='dyad' is j [with values 1 to, at most, F*(F-1)/2],
Note while in the notation of S&K, C129 is k.
Note Definition of the model at levels 1 and 2:
dumm C135 C111 C112
name C111 'obs1' C112 'obs2'
resp C131
expl 1 'const' 'obs1' 'obs2'
switch B20
CASE 1:
expl 1 C301-CB7
endswitch
fpar 0 'obs1' 'obs2'
setv 2 'obs1' 'obs2'
gene 4 c139
calc c139 = 0*c139
edit 1 c139 1
edit 3 c139 -1
rcon c139
switch B22
CASE 1:
setv 3 'const'
endswitch
calc c140 = c139
Note c140 is a reserve vector for the constraints of the random part.
batch 1
tole 4
method rigls
maxi 100
pref 0
postf 0
echo 1
Note Estimates for the model with random dyad effects only,
Note and without actor or partner effects.
start
fixe
rand
like
echo 0
Note definition of the crossed random effects:
calc B21 = 140+2*B14
calc B16 = 141+B14
calc B17 = 140+B14
rcon c139
setx 'const' 'conss' 3 C132 C141-CB21 C139
dummies C133 CB16-CB21
echo 1
Note Now the model with correlated random actor and partner effects.
echo 0
switch B22
CASE 0:
echo 1
Note This is model (1) and also (2) in Snijders & Kenny (1999),
Note defined as (11.15) and also (11.16) in Snijders & Bosker (1999);
Note with covariates it is model (5) in Snijders & Kenny, 1999.
echo 0
LEAVE
CASE 1:
switch B20
CASE 0:
echo 1
Note This is model (6)-(8) in Snijders & Kenny (1999).
echo 0
LEAVE
CASE 1:
echo 1
Note This is model (6)-(8) in Snijders & Kenny (1999), plus covariates.
echo 0
endswitch
endswitch
echo 1
start
fixe
rand
like
echo 0
calc B18 = 3*B14 + 4 + B22
calc B19 = B21+1
gene B18 CB19
calc CB19 = 0*CB19
Note this was a way of making a column of length B18, filled with 0
calc B18 = 1 + B22
edit B18 CB19 1
calc B18 = B18 + 2
edit B18 CB19 -1
append C139 CB19 C139
erase CB19
echo 1
Note Now a model in which actor and partner variances are equal:
start
fixe
rand
like
Re: Run social relations model macro using runmlwin
Posted: Fri Oct 11, 2013 3:43 pm
by GeorgeLeckie
Hi Kurt,
The macro simply sets up a particular multilevel model which you could equally set up via the standard point-and-click interface (i.e., GUI) in MLwiN or via the runmlwin command in Stata
To understand how to fit the model the best thing to do is to read the Snijders and Kenny (1999) journal article rather than the MLwiN macro.
Make sure you understand the statistical model and the clever way they propose implementing it, only then try specifying the model using runmlwin
Perhaps Snijders and Kenny make example data available allowing you to replicate their results using the runmlwin command?
If you get stuck please post your attempt at the runmlwin syntax with their data and we can then see where you are getting stuck.
Best wishes
George