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

st: RE: RE: macro length exceeded

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: macro length exceeded
Date   Sun, 8 Nov 2009 16:23:23 -0000

See also the generic 

Is there a way to tell Stata to try all values of a particular variable
in a foreach statement without specifying them?

[email protected] 

Martin Weiss

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
with 128040 individuals (via -set obs 128040- at the top of the do
But there is an easier solution: Omit the -levelsof- line which causes
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
This is of course a time intensive procedure, but it is a way to
the limitations imposed by the macro length. It only works if the
runs from 1 to 128040, i.e. no gaps in there. -levelsof- would have put
levels of the variable into the macro, that is why I went for it in the
first place...

Vincenzo Carrieri

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?

*   For searches and help try:

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