Home » Data » Dataset use in Stata » Too long command in Stata?
Too long command in Stata? [message #11605] |
Sun, 15 January 2017 08:56 ![Go to next message Go to next message](/theme/default/images/down.png) |
nwegbus
Messages: 15 Registered: December 2015
|
Member |
|
|
Hello,
I'm a doctoral student writing my dissertation using the Nigeria DHS 2013 and Stata 13. I'm trying to construct a variable -achild- (actual number of children) using 4 observed variables in the dataset -v202, v203, v204 and v205- which represent "sons at home, daughters at home, sons elsewhere and daughters elsewhere' respectively.
I'm doing this by generating my new variable and then doing a series of "replace ifs". Since some women have as many as 11 children in any of the four categories, my commands are extremely long and this is causing Stata to return this message:
"error . . . . . . . . . . . . . . . . . . . . . . . . Return code 130
expression too long;
too many SUMs;
In the first case, you specified an expression that is too long
for Stata to process -- the expression contains more than 249
pairs of nested parentheses or more than 800 dyadic operators.
(For Small Stata, the limit is 66 dyadic operators.) Break
the expression into smaller parts. In the second case, the
expression contains more than 5 sum() functions. This
expression, too, will have to be broken into smaller parts."
****Edited to add****
I have already tried using the "///" and "*/" symbols and breaking up the command into seven shorter lines instead of just four. It's still not working.
I'm convinced there is a more efficient way of doing what I'm trying to do in a shorter time, and using less lengthy commands. I just can't seem to figure it out.
Any guidance and suggestions/links would be highly appreciated.
Thank you
SN
[Updated on: Tue, 17 January 2017 15:22] Report message to a moderator
|
|
|
Re: Too long command in Stata? [message #11622 is a reply to message #11605] |
Tue, 17 January 2017 17:06 ![Go to previous message Go to previous message](/theme/default/images/up.png) ![Go to next message Go to next message](/theme/default/images/down.png) |
Bridgette-DHS
Messages: 3151 Registered: February 2013
|
Senior Member |
|
|
Following is a response from Senior DHS Stata Specialist, Tom Pullum:
The way to deal with long lines is with #delimit. (Enter "help delimit".) Here's an example of how you change to a long line with a semicolon an the delimiter and then back to regular lines in a program:
#delimit ;
Enter your long line here
;
#delimit cr
You can have multiple lines between the two "#delimit" statements, but there must be a semicolon at the end of, or after, each such line.
The normal delimiter is an end of line mark, which is not visible in a text file, but is referred to as "cr" for "carriage return", harking back to the days of typewriters.
[Updated on: Thu, 19 January 2017 11:34] Report message to a moderator
|
|
|
|
Re: Too long command in Stata? [message #11636 is a reply to message #11635] |
Thu, 19 January 2017 13:12 ![Go to previous message Go to previous message](/theme/default/images/up.png) ![Go to next message Go to next message](/theme/default/images/down.png) |
Bridgette-DHS
Messages: 3151 Registered: February 2013
|
Senior Member |
|
|
Following is another response from Senior DHS Stata Specialist, Tom Pullum:
Did you read the error statement? As it says, this "line" has too many characters and too many components. Beyond that, it is very ambiguous because you do not have parentheses. However, even if it were shorter, it would not execute. Can't you see that something like "if A & B | C & D" is ambiguous? Such a statement could be interpreted as "if (A & B) | (C & D)" or as "if A & (B | C) & D" or a few other variations. What is it that you want to do? You certainly do not need to run through all possible combinations of v202, v203, v204, and v205, which is what you seem to be doing. If you will insert left and right parentheses to remove the ambiguity, I will then suggest how you could reduce the length of the line.
|
|
|
|
|
Re: Too long command in Stata? [message #11667 is a reply to message #11663] |
Mon, 23 January 2017 12:03 ![Go to previous message Go to previous message](/theme/default/images/up.png) |
nwegbus
Messages: 15 Registered: December 2015
|
Member |
|
|
Thank you. You are correct. I did not know this. I'm learning Stata, as I go along, by actually doing real life stuff with it. True, I've had a lot of Stata classes, but I'm one of those people that learn best when I can apply abstract stuff to real life things that I actually care about.
Once again, thank you for all you do :)
SN
|
|
|
Goto Forum:
Current Time: Sun Sep 1 11:34:10 Coordinated Universal Time 2024
|