Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: How to compose constraint with a series of variables?


From   Jorge Eduardo Pérez Pérez <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: How to compose constraint with a series of variables?
Date   Sun, 20 Mar 2011 00:32:38 -0400

clear
set obs 1000
gen y=uniform()
forvalues i=1(1)50 {
	gen phrase`i'=uniform()
	gen x`i'=uniform()
}
glo sum ""
local i=1
foreach x of varlist phrase* {
	if `i'==1 {
		glo sum "$sum [`x']"
	}
	else {
		glo sum "${sum} + [`x']"
	}
	local i=`i'+1 	
}
constraint define 1 $sum = 0
cnsreg y phrase* x*, constraints(1)
_______________________
Jorge Eduardo Pérez Pérez


On Sat, Mar 19, 2011 at 9:20 PM, Muyang Zhang <[email protected]> wrote:
> I am only imposing one constraint: the sum of those variables is 0.
>
> On Sat, Mar 19, 2011 at 7:43 PM, Nick Cox <[email protected]> wrote:
>> You can't, or so I believe. I think the best you can do is to define
>> many constraints within a loop. For example, suppose you had variables
>> v1-v1000 and you wanted to impose the same constraint on each. A
>> skeleton could be
>>
>> forval i = 1/1000 {
>> constraint `i' v`i' = < whatever>
>> }
>>
>> That said, I don't how successful you are likely to be imposing
>> hundreds of constraints.
>>
>> Nick
>>
>> On Sat, Mar 19, 2011 at 9:56 PM, Muyang Zhang <[email protected]> wrote:
>>>
>>> I wish to set constraints in regression. I know usually it can be
>>> implemented by the -constraint- command.
>>>
>>> But my problem is that I have a series of variables (over 1000)
>>> starting with the same phrase followed by numbers. How can I compose
>>> constraints with -*- operator?
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>>
>
>
>
> --
> Zhang Muyang
> China Center for Economic Research
> Peking University
> Beijing, 100871
> China.
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index