[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: macro length exceeded

From   "Martin Weiss" <>
To   <>
Subject   st: RE: macro length exceeded
Date   Sat, 7 Nov 2009 13:24:44 +0100


You do not have to -set obs- in any way, as _you_ have the data that you
want to use. I do not, so I had to make them up to test ideas for you.

Anyway, the -macro length- is also exceeded on my machine when I try to work
with 128040 individuals (via -set obs 128040- at the top of the do file).
But there is an easier solution: Omit the -levelsof- line which causes the
error. Set up the loop as

qui forvalues id=1/`=_N'{
       drop `touse'

which lets it run through all the rows of your dataset, one after another.
This is of course a time intensive procedure, but it is a way to circumvent
the limitations imposed by the macro length. It only works if the -personid-
runs from 1 to 128040, i.e. no gaps in there. -levelsof- would have put the
levels of the variable into the macro, that is why I went for it in the
first place...


-----Original Message-----
[] On Behalf Of Vincenzo Carrieri
Sent: Samstag, 7. November 2009 11:10
Subject: st: macro length exceeded

Dear statalisters,
I have tried to run the loop one statalister suggested me to assign
the mean of income calculated to the person with
same education, same region, same activity and falling in an age
interval. The loop suggested me is the following:

set obs 1000
gen personid=_n

gen byte region= irecode(_n,0,1000,5000,10000)
gen income= rnormal(0,100)+1500
gen byte education=9+int(8*runiform())
gen byte activity=int(10*runiform())
gen age=20+int(10*runiform())

//generate var to be filled later on
gen meanincome=.
//also count the number of "peers"
gen count=.

qui levelsof personid

qui foreach id of numlist `r(levels)'{
       tempvar touse
       gen byte `touse'=region==region[`id'] & /*
       */ education==education[`id'] & /*
       */ activity==activity[`id'] & /*
       */ inrange(age, age[`id']-5, age[`id']+5)
       su income if `touse', mean
       replace meanincome=r(mean) if `touse'
       replace count=r(N) if `touse'

 The problem is that I have 128040 individuals and I cannot set obs
1000 as the statalister suggested me ( stata gives me this error:
obs must be between 128040 and 1060356). then If I skip to set obs and
I work with all my 128040 individuals, stata says me: macro length

Ho can I solve this problem? is it because my data-set is too big? I
have set mem 800m and matsize 90, is it not enough?

Many thanks

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2023 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index