Page 1 of 2
Three-level growth using Instrumental Variable
Posted: Thu May 30, 2013 7:48 pm
by drddtorres
Hi, all,
I'm new to MLwiN (just had it ordered for my office desktop) and will likely be running the program from within Stata. I found out, though, that I need to use the -ivmlwin- macro to make use of the instrumental variables (IV) approach. I'd very much appreciate an example of how the code should be setup.
About the data: I have repeated measures for students nested within schools. There are time-varying and time-invariant variables at levels 1 and 2 and there are also a few variables at the school level. One of my time-invariant variables is endogenous and binary.
Thanks in advance

,
Diego Torres
Re: Three-level growth using Instrumental Variable
Posted: Fri May 31, 2013 8:37 am
by GeorgeLeckie
Hi Diego,
You can use runmlwin to fit any model which you can be specified manually in MLwiN (either via the GUI or via a macro). So you should be able to fit whatever models are specified using the ivmlwin which you refer to. This macro can be found at
http://www.bristol.ac.uk/cmm/team/fielding.html
I am not familiar with this macro, but I suspect it will simply be doing 2SLS and will only be set up for the case of two-level model with a continuous outcome and an endogenous continuous variable at level-1, but I am only guessing.
It sounds like you have a three-level model with a continuous outcome and a binary endogenous variable at level-2.
I am not sure whether simply specifying a first stage level-2 equation for the binary endogenous variable and plugging the predicted probabilities (or perhaps predicted outcomes) in place of the binary endogenous variable in the three-level model of interest is what you want to do. That is I do not know whether the 2SLS approach carries over to the case of binary endogenous variables. However, I am sure you can find lots in the literature on this topic.
Best wishes
George
Re: Three-level growth using Instrumental Variable
Posted: Mon Jun 03, 2013 1:30 pm
by drddtorres
You're correct. I am planning to do a 2 stage least squares analysis. I don't know much about the macro either, and, like I said, I'm fairly new to the approach. I was told by a couple folks on the Statalist site that, for the model I want to run, I'd need to MLwiN as it can handle much more complex setups. I explained that my setup is a three-level model with a binary endogenous predictor and a continuous outcome.
If there's no one else familiar with the ivmlwin macro, should I perhaps address the question to those on the MLwiN forum? I've got the data ready to go, but I want to make sure I'm not wasting my time doing things wrong.
Diego
Re: Three-level growth using Instrumental Variable
Posted: Tue Jun 04, 2013 10:23 am
by GeorgeLeckie
Hi Diego,
I'm afraid no one in the group is familiar with this macro. However, I have taken a quick look with a colleague and as far as we can work out it should in theory work for your model of interest: A continuous outcome and a binary endogenous variable at level-2. Note that the macro is only implemented for the case where you have a single instrument per endogenous regressor.
If one could work out all the steps of this macro, then one could in theory attempt to get this working via multiple calls of runmlwin in a loop and so on, but this would not be trivial. I therefore think that your best bet, should you want to proceed would be to see if you could get the macro working directly.
Best wishes
George
Re: Three-level growth using Instrumental Variable
Posted: Tue Jun 04, 2013 11:50 am
by ChrisCharlton
Just to add to this in case you did want to run this macro directly in MLwiN - there have been a number of changes to MLwiN since these macros were originally written, for example to the columns where estimates are stored. I have updated the macros in the attached file to match these changes. Also note that there are a couple of bugs in version 2.27 of MLwiN in some of the lesser used commands which affect these macros, so you would either have to use an older version of MLwiN, or wait for the next release.
To use these macros:
1) extract the files to a location of your choice
2) open your data and set up your model (check you don't use columns c300-c310 as these are used by the macros)
3) open the Options->Directories menu
4) click "User defined settings"
5) enter the path to the location where you extracted the files into the "fpath" box
6) enter pre.iv into "pre file"
7) enter post.iv into "post file"
8) click "start" to initialise the "fixvars" and "ivset" columns
9) edit values in the "ivset" column to match the variables that you want to use
10) click "start" to run the model
Re: Three-level growth using Instrumental Variable
Posted: Wed Jun 05, 2013 6:22 pm
by drddtorres
Thanks so much, fellas. I will attempt to run the model directly from MLwiN, following your suggestion.
Diego
Re: Three-level growth using Instrumental Variable
Posted: Tue Jun 11, 2013 11:54 am
by GeorgeLeckie
Hi Diego,
My colleague Chris and I have taken a longer look at the IV macro. It looks like the macro does the following...
(1) Fits a single-level IV regression version of the model of interest (just like -ivregress-).
(2) Constrain the fixed part parameters in the model of interest to equal the estimates from (1) and then estimate the random part parameters (i.e. the variance components).
(3) Calculate adjusted standard errors for the fixed part parameters estimated in (1) and specified in (2) which reflect the degree of clustering in the data as estimated by the variance components in (2).
While I have described what the macro does in terms of a two-level random-intercept model, the above macro will also work with a three-level random-slopes model and other continuous response models.
I hope that helps.
George
Re: Three-level growth using Instrumental Variable
Posted: Tue Jun 11, 2013 1:19 pm
by ChrisCharlton
In case you did want to run this directly with runmlwin I have done what should be a direct translation of the macro into a .ado file (attached). To use this you would append the prefix:
before the runmlwin command, where varlist contains the variables that you would reference in the IVSET column when using the macros in MLwiN.
An example command would be:
Code: Select all
iv cons girl: runmlwin normexam cons standlrt, level2(school: cons) level1(student: cons) nopause
Note that although this gives the same results as the macros for the models that I tested I am unfamiliar with the theory behind what it is doing so, as with the macros, you would use this at your own risk.
Re: Three-level growth using Instrumental Variable
Posted: Thu Jun 20, 2013 6:03 pm
by drddtorres
Chris,
Since I've been able to run a complete IV model in MLwiN 2.26 (I had to downgrade), I want to try running it from within Stata using the .ado file you created. I've tried the example you've given, which uses the dataset called up with the runmlwin examples. I just want to make sure I understand what is supposed to come after the -iv- portion of your command. You say that "varlist contains the variables that you would reference in the IVSET column when using the macro in MLwiN." How exactly am I to reference my instrument and the variable it's being used for? Is the cons always in that varlist?
The variable I'm instrumenting for is called 'diffsch' while the instrument is called 'diffdist.' Should my model be set up thusly:
iv diffsch diffdist: ...
Diego
Re: Three-level growth using Instrumental Variable
Posted: Thu Jun 20, 2013 6:36 pm
by ChrisCharlton
The variables after the iv are either the original predictors, or the corresponding instrument (and correspond to the IVSET column that you used in the MLwiN macro), so for you example you would want something like:
Code: Select all
iv cons diffdist: runmlwin resp cons diffsch, level1(l1id: cons) ...
If you run the same model that you have working already in MLwiN you should be able to check that the results are the same and that you have set it up correctly.