classification (N-level ID) issue

Welcome to the forum for Stat-JR users. Feel free to post your question about Stat-JR here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

We will add further support to the Stat-JR website, such as FAQs and tutorials, as soon as it is available; the Stat-JR website can be found here: http://www.bristol.ac.uk/cmm/software/statjr/
yongjookim78
Posts: 45
Joined: Tue Jan 10, 2017 3:36 am

classification (N-level ID) issue

Post by yongjookim78 »

Hello,

Just finished all installation procedures and started to run Stat-JR based on Chrome.

First, I uploaded the DTA file that contains missing information.

Then, based on the manual, I chose "Template" => "N-Level" => "NLevelMod" => "Use" to build four-level models (as my model of interest is a four-level random intercept model although the missing is only at level 1).

After I put "4" as the number of classification, I couldn't find some of "ID" variables (i.e., individual ID, household ID, and PSU) from the "classification" bar. However, I did find those variables from the "response" bar.

The same issue happened when I tried to use other template such as 2-Level.

I am wondering how I can address this part. Would appreciate your supports!

Best wishes,
Yongjoo
ChrisCharlton
Posts: 1348
Joined: Mon Oct 19, 2009 10:34 am

Re: classification (N-level ID) issue

Post by ChrisCharlton »

For these templates the number of classifications that you specify refers to higher level classifications, i.e. you don't need to specify a level-1 unit classification. For variables to be offered as options for the classifications they need to be of an integer type (i.e. none of the values contain any decimals). I would suggest checking that this is the case for the variables that you are trying to use.
yongjookim78
Posts: 45
Joined: Tue Jan 10, 2017 3:36 am

Re: classification (N-level ID) issue

Post by yongjookim78 »

I just quickly checked the DTA file, and it seems those (individual, household, and PSU IDs) variables were coded as "character" values (i.e., A010101). I am wondering what might be a good solution to address this part, and would appreciate your help! :)
Best wishes,
Yongjoo
ChrisCharlton
Posts: 1348
Joined: Mon Oct 19, 2009 10:34 am

Re: classification (N-level ID) issue

Post by ChrisCharlton »

If you have Stata then you could convert them to numeric variables using the encode command (see https://www.stata.com/help.cgi?encode).

Alternatively if you just open the .dta file in MLwiN then it will convert any string variables into numeric codes, with the old string used as the value label. You can then reexport the data from MLwiN for use in Stat-JR.
yongjookim78
Posts: 45
Joined: Tue Jan 10, 2017 3:36 am

Re: classification (N-level ID) issue

Post by yongjookim78 »

Thank you so much Chris! Both sound like excellent suggestions!
I just tried the first option with Stata encode command and Stat-JR started to recognize those variables finally! Then, I've got a couple follow-up questions.

First, if my original multilevel is a four-level (individual-household-psu- wider geographic area), then how many "classification" should I assign? Is it "four" like MOI or "three" as you mentioned in the earlier discussion?

Second, after assigning the number of classification, in terms of model specification, I am wondering whether I need to build the exactly same model as MOI (which did not include potential mediator variables), or it might be better to include more variables (i.e., mediator variables or anything that might provide relevant information to the overall imputation procedure?)

Thank you very much again!

Best wishes,
Yongjoo
yongjookim78
Posts: 45
Joined: Tue Jan 10, 2017 3:36 am

Re: classification (N-level ID) issue

Post by yongjookim78 »

Hello,

While trying to run Stat-JR, I've got an error message and would appreciate your supports!

1. Setting
- I've uploaded a dta file for Stat-JR.
- I chose "N-level" with "NLevelMod" option as my MOI is a four-level linear model.
- I set the highest level (level 2) as classification 1, second highest level (level 3) as classification 2, and second lowest level (level 2) as classification 3.
- When I run this, I've got an error message as below.

2. Error message
Traceback (most recent call last):
File "webtest.py", line 375, in go
File "C:\StatJR\packages\eStat.py", line 1196, in run
self.runcode(str(self.eng.outputs['modelcode.cpp'].content), self.vars[chainnum], self.data)
File "C:\StatJR\packages\eStat.py", line 832, in runcode
result = runcode(code, self.scode, locals, globals)
File "O:\repo\stat-jr\src\lib\EStat\Utils.py", line 141, in runcode
File "c:\Python27\lib\site-packages\weave\inline_tools.py", line 366, in inline
File "c:\Python27\lib\site-packages\weave\inline_tools.py", line 496, in compile_function
File "c:\Python27\lib\site-packages\weave\ext_tools.py", line 373, in compile
File "c:\Python27\lib\site-packages\weave\build_tools.py", line 279, in build_extension
File "c:\Python27\lib\site-packages\numpy\distutils\core.py", line 169, in setup
File "c:\Python27\lib\distutils\core.py", line 166, in setup
CompileError: error: Command "g++ -O2 -Wall -DNPY_MINGW_USE_CUSTOM_MSVCR -D__MSVCRT_VERSION__=0x0900 -IC:\StatJR\src\lib\EStat\templates -IC:\StatJR\src\apps\tree\include -IC:\StatJR\src\apps\tree\include\scxx -IC:\StatJR\src\apps\tree\tree.exe\numpy\core\include -IC:\StatJR\src\apps\tree\include -IC:\StatJR\src\apps\tree\PC -c C:\StatJR\src\lib\EStat\templates\rng_simple.cpp -o c:\users\yok880\appdata\local\temp\scipy-yok880-_tddu8\python27_intermediate\compiler_e433b115c443362274443bf1b7e873b5\Release\statjr\src\lib\estat\templates\rng_simple.o -w -O3 -std=c++11" failed with exit status 1

Would appreciate your support!

Best wishes,
Yongjoo
ChrisCharlton
Posts: 1348
Joined: Mon Oct 19, 2009 10:34 am

Re: classification (N-level ID) issue

Post by ChrisCharlton »

Could you please check the black command window that initially opened when you loaded Stat-JR and let me know if there are any further messages reported by the compiler?
RinaStatistics
Posts: 4
Joined: Tue Oct 02, 2018 9:45 am

Re: classification (N-level ID) issue

Post by RinaStatistics »

Hi,
I have the same error message and when I check the black command window there are this kind of message:

….\python27_compiled\sc_c3d528436cdc971e035966e30b71f59b2.cpp: In function 'PyObject* compiled_func(PyObject*, PyObject*)':
….\python27_compiled\sc_c3d528436cdc971e035966e30b71f59b2.cpp:5527:49: error: 'mat_x1_5_2' was not declared in this scope
for (int k = 0; k < mat_x1_5_2.cols(); k++) {
^~~~~~~~~~
….\python27_compiled\sc_c3d528436cdc971e035966e30b71f59b2.cpp:5527:49: note: suggested alternative: 'mat_x1_5_1'
for (int k = 0; k < mat_x1_5_2.cols(); k++) {


Thank you for any help!
Rina
ChrisCharlton
Posts: 1348
Joined: Mon Oct 19, 2009 10:34 am

Re: classification (N-level ID) issue

Post by ChrisCharlton »

Could you let us know the structure of the model that you are trying to fit? Could you also confirm that any categorical variables in your data are numbered consecutively from zero?
RinaStatistics
Posts: 4
Joined: Tue Oct 02, 2018 9:45 am

Re: classification (N-level ID) issue

Post by RinaStatistics »

The following is the string input:
{'want2': 'No', 'numimpute': '10', 'bin1_5': 'Unordered', 'ncatsPOLITICAL': '3', 'imputefirst': '1000', 'MOIlevel': '2 levels', 'bin1_3': 'Binary', 'bin1_2': 'Binary', 'bin1_1': 'Normal', 'bin1_7': 'Normal', 'bin1_6': 'Normal', 'iterations': '250', 'bin1_4': 'Unordered', 'bin1_9': 'Normal', 'bin1_8': 'Normal', 'MOIslope': 'Yes', 'condmarg': 'Yes', 'ximp1_4_0': 'Cons', 'numlevs': 'Yes', 'burnin': '100', 'priors': 'Uniform', 'ximp1_1': 'Cons', 'ximp1_0': 'Cons', 'ximp1_2': 'Cons', 'ximp1_5': 'Cons', 'ximp1_7': 'Cons', 'ximp1_6': 'Cons', 'ximp1_3_1': 'Cons', 'ximp1_3_0': 'Cons', 'ximp1_4_1': 'Cons', 'ximp1_8': 'Cons', 'x2': 'Education:cat,UNIVERSALISM,SELFDIRECTION,POWER,CONSERVATION,Cons', 'L2ID': 'cntry', 'yimp1': 'genver,gndr,migration,Education,POLITICAL,UNIVERSALISM,SELFDIRECTION,POWER,CONSERVATION', 'ncatsEducation': '3', 'imputeevery': '50', 'MOIdist': 'Normal', 'y': 'trstplc', 'x': 'gndr:cat,migration:cat,Education:cat,Alter,POLITICAL,CPI2011,UNIVERSALISM,SELFDIRECTION,POWER,CONSERVATION,Cons'}

and yes all categorial are from 0.

Thanks for your help!
Post Reply