I have two sets of categorical variables, each of which takes on a small number of integer values. I'm trying to form all interactions between members of the two sets using the -xi- command at line 4 of the loop below. Ultimately the interactions will be fed into a lasso regression, but at the moment, just generating them results in a "characteristic contents too long" error.
I haven't found much on this error. This thread https://www.statalist.org/forums/for...tents-too-long discusses the error in the context of -reshape-, but it seems pretty specific to that command.
From the sound of the error, and the discussion in the above thread, I thought I had inadvertently tried to construct interactions with an id variable or something else with lots of values. The table at the bottom shows that this is not the case, since all of my categorical variables take on values between 0 and 4.
Finally, the prefix() option of -xi- allows for a 4-character prefix. The largest prefix that results from the loop is _378, so it looks like I should be ok there.
I haven't found much on this error. This thread https://www.statalist.org/forums/for...tents-too-long discusses the error in the context of -reshape-, but it seems pretty specific to that command.
From the sound of the error, and the discussion in the above thread, I thought I had inadvertently tried to construct interactions with an id variable or something else with lots of values. The table at the bottom shows that this is not the case, since all of my categorical variables take on values between 0 and 4.
Finally, the prefix() option of -xi- allows for a 4-character prefix. The largest prefix that results from the loop is _378, so it looks like I should be ok there.
Code:
. *** loop test
.
. qui d,s
. disp r(k)
100
.
. local n=0
. capture drop _*
. unab qtest : $dashqs
. unab chtest : $chcat1
. foreach q of local qtest {
2. foreach v of local chtest {
3. local n=`n'+1
4. qui xi i.`q'*i.`v',prefix(_`n') noomit
5. }
6. }
characteristic contents too long
The maximum value of the contents is 67,784.
. qui d _*,full
. disp r(k)
5446
Code:
. sum $dashqs Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- question1 | 16,203 .3972721 .7096666 0 2 question2 | 16,203 .6209344 .7598174 0 2 question3 | 16,203 .6661729 .7682009 0 2 question4 | 16,203 .4974387 .7898037 0 2 question5 | 16,203 .5583534 .7951362 0 2 -------------+--------------------------------------------------------- question6 | 16,203 .8128742 .717489 0 2 question7 | 16,203 .4954638 .7745655 0 2 question8 | 16,203 .5668703 .790337 0 2 question9 | 16,203 .5152132 .7729136 0 2 question10 | 16,203 .5037956 .7752067 0 2 -------------+--------------------------------------------------------- question11 | 16,203 .4039375 .7872436 0 2 question12 | 16,203 .4059742 .7896028 0 2 question13 | 16,203 .5898908 .7954562 0 2 question14 | 16,203 .5867432 .7968132 0 2 question15 | 16,203 .6465469 .7919159 0 2 -------------+--------------------------------------------------------- question16 | 16,203 .4920694 .8082302 0 2 question17 | 16,203 .5070049 .8101456 0 2 question18 | 16,203 .5339752 .8102253 0 2 question19 | 16,203 .4866383 .8143213 0 2 question20 | 16,203 .4383756 .8070643 0 2 -------------+--------------------------------------------------------- question21 | 16,203 .5215701 .8104981 0 2 question22 | 16,203 .438499 .8071502 0 2 question23 | 16,203 .5563167 .8025451 0 2 question24 | 16,203 .760785 .7557867 0 2 question25 | 16,203 .5861877 .8089423 0 2 -------------+--------------------------------------------------------- question26 | 16,203 .5074986 .8086924 0 2 question27 | 16,203 .826637 .7211523 0 2 . sum $chcat1 Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- atvictimhome | 16,203 .7191261 .5818269 0 2 expartners | 16,203 .6197001 .6068465 0 2 familyperp~r | 16,203 .0002469 .0157106 0 1 gendervictim | 16,203 .1627476 .3691467 0 1 perpetrato~l | 16,203 .3179041 .4656764 0 1 -------------+--------------------------------------------------------- perpetrato~e | 16,203 1.435228 .9764152 0 4 roleswitch | 16,203 .2380423 .4258983 0 1 victimdrugs | 16,203 .0209838 .1433343 0 1 victiminjury | 16,203 .10424 .305581 0 1 victim_cat~e | 16,203 1.284762 .9585312 0 4 -------------+--------------------------------------------------------- victimalco~l | 16,203 .2095908 .4070292 0 1 perpetrato~s | 16,203 .0767142 .2661456 0 1 perpetrato~y | 16,203 .0271555 .1625413 0 1 perpetrato~e | 16,203 1.435228 .9764152 0 4
Comment