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: Nlsur Quaids


From   Ana <[email protected]>
To   [email protected]
Subject   Re: st: Nlsur Quaids
Date   Tue, 19 Jul 2011 16:16:18 -0300

Brian, Thank you very much for your prompt response. I've corrected
this silly mistake of mine, but I'm getting another one now.

Where does the restriction come from?
Actually, I using your code (Brain Poi, 2008) to estimate a seven
group demand system and I want to apply/test a test developed by
Browning and Chiappori (1998). Therefore, I want to test the following
restrictions (see in the following program routine I am sendig
attached):

   scalar `g81' = `g13'*`g24' - `g13'*`g42' - `g31'*`g24' + `g31'*`g42'
   scalar `g82' = `g14'*`g23' - `g14'*`g32' - `g41'*`g23' + `g41'*`g32'
   scalar `g83' = `g12' - `g21'
   scalar `g34' = `g43' + `g81'/`g83' - `g82'/`g83'
  ....an so on.

The problem is that I'm getting r(480) indicanting that I have missing
values or wrong initial values.
Can you guess how can I correct this mistake?

My program nlsur routine:

program nlsurquaidssrum

	version 11.1
	
	syntax varlist(min=21 max=21) if, at(name)
	
	// tokenize `varlist'
	args w1 w2 w3 w4 w5 w6 lnp1 lnp2 lnp3 lnp4 lnp5 lnp6 lnp7 lnm ano
agechef escchef none respropria resid residsq
	
	// With seven goods, there are 72 parameters that can be
	// estimated, after eliminating one of the goods and
	// imposing adding up, symmetry, and homogeneity
	// constraints, in the QUAIDS model
	// Here, we extract those parameters from the `at'
	// vector, and impose constraints as we go along

	tempname a1 a2 a3 a4 a5 a6 a7
	scalar `a1' = `at'[1,1]	
	scalar `a2' = `at'[1,2]	
	scalar `a3' = `at'[1,3]
	scalar `a4' = `at'[1,4]
	scalar `a5' = `at'[1,5]
	scalar `a6' = `at'[1,6]
	scalar `a7' = 1 - `a1' - `a2' - `a3' - `a4' - `a5' - `a6'
	
	tempname b1 b2 b3 b4 b5 b6 b7
	scalar `b1' = `at'[1,7]
	scalar `b2' = `at'[1,8]
	scalar `b3' = `at'[1,9]
	scalar `b4' = `at'[1,10]
	scalar `b5' = `at'[1,11]
	scalar `b6' = `at'[1,12]
	scalar `b7' = -`b1' - `b2' - `b3' - `b4' - `b5' - `b6'
	
	tempname g11 g12 g13 g14 g15 g16 g17
	tempname g21 g22 g23 g24 g25 g26 g27
	tempname g31 g32 g33 g34 g35 g36 g37
	tempname g41 g42 g43 g44 g45 g46 g47
	tempname g51 g52 g53 g54 g55 g56 g57
	tempname g61 g62 g63 g64 g65 g66 g67
	tempname g71 g72 g73 g74 g75 g76 g77
	scalar `g11' = `at'[1,13]
	scalar `g12' = `at'[1,14]
	scalar `g13' = `at'[1,15]
	scalar `g14' = `at'[1,16]
	scalar `g15' = `at'[1,17]
	scalar `g16' = `at'[1,18]
	scalar `g17' = -`g11' - `g12' - `g13' -`g14' - `g15' - `g16'

	// scalar `g21' = `g12'
	scalar `g21' = `at'[1,19]
	scalar `g22' = `at'[1,20]
	scalar `g23' = `at'[1,21]
	scalar `g24' = `at'[1,22]
	scalar `g25' = `at'[1,23]
	scalar `g26' = `at'[1,24]
	scalar `g27' = -`g21' - `g22' - `g23' - `g24' - `g25' - `g26'

	// scalar `g31' = `g13'
	// scalar `g32' = `g23'
	scalar `g31' = `at'[1,25]
	scalar `g32' = `at'[1,26]
	scalar `g33' = `at'[1,27]
	scalar `g34' = `at'[1,28]
	scalar `g35' = `at'[1,29]
	scalar `g36' = `at'[1,30]
	scalar `g37' = -`g31' - `g32' - `g33' - `g34' - `g35' - `g36'

	// scalar `g41' = `g14'
	// scalar `g42' = `g24'
	// scalar `g43' = `g34'
	scalar `g41' = `at'[1,31]
	scalar `g42' = `at'[1,32]
	scalar `g43' = `at'[1,33]
	scalar `g44' = `at'[1,34]
	scalar `g45' = `at'[1,35]
	scalar `g46' = `at'[1,36]
	scalar `g47' = -`g41' - `g42' - `g43' - `g44' - `g45' - `g46'
	
	// scalar `g51' = `g15'
	// scalar `g52' = `g25'
	// scalar `g53' = `g35'
	// scalar `g54' = `g45'
	scalar `g51' = `at'[1,37]
	scalar `g52' = `at'[1,38]
	scalar `g53' = `at'[1,39]
	scalar `g54' = `at'[1,40]
	scalar `g55' = `at'[1,41]
	scalar `g56' = `at'[1,42]
	scalar `g57' = -`g51' - `g52' - `g53' - `g54' - `g55' - `g56'
	
	// scalar `g61' = `g16'
	// scalar `g62' = `g26'
	// scalar `g63' = `g36'
	// scalar `g64' = `g46'
	// scalar `g65' = `g56'
	scalar `g61' = `at'[1,43]
	scalar `g62' = `at'[1,44]
	scalar `g63' = `at'[1,45]
	scalar `g64' = `at'[1,46]
	scalar `g65' = `at'[1,47]
	scalar `g66' = `at'[1,48]
	scalar `g67' = -`g61' - `g62' - `g63' - `g64' - `g65' - `g66'
	
	// scalar `g71' = `g17'
	// scalar `g72' = `g27'
	// scalar `g73' = `g37'
	// scalar `g74' = `g47'
	// scalar `g75' = `g57'
	// scalar `g76' = `g67'
	scalar `g71' = `at'[1,49]
	scalar `g72' = `at'[1,50]
	scalar `g73' = `at'[1,51]
	scalar `g74' = `at'[1,52]
	scalar `g75' = `at'[1,53]
	scalar `g76' = `at'[1,54]
	scalar `g77' = -`g71' - `g72' - `g73' - `g74' - `g75' - `g76'

   // Browning e Chiappori
   tempname g81 g82 g83
   scalar `g81' = `g13'*`g24' - `g13'*`g42' - `g31'*`g24' + `g31'*`g42'
   scalar `g82' = `g14'*`g23' - `g14'*`g32' - `g41'*`g23' + `g41'*`g32'
   scalar `g83' = `g12' - `g21'
   scalar `g34' = `g43' + `g81'/`g83' - `g82'/`g83'
   // scalar `g34' - `g43' = ((`g13' - `g31')*(`g24' - `g42') - (`g14'
- `g41')*(`g23' - `g32'))/(`g12' - `g21'))

   tempname g91  g92
   scalar `g91' = `g13'*`g25' - `g13'*`g52' - `g31'*`g25' + `g31'*`g52'
   scalar `g92' = `g15'*`g23' - `g15'*`g32' - `g51'*`g23' + `g51'*`g32'
   scalar `g35' = `g53' + `g91'/`g83' - `g92'/`g83'
   // scalar `g35' - `g53' = ((`g13' - `g31')*(`g25' - `g52') - (`g15'
- `g51')*(`g23' - `g32'))/(`g12' - `g21'))

   tempname g101  g102
   scalar `g101' = `g13'*`g26' - `g13'*`g62' - `g31'*`g26' + `g31'*`g62'
   scalar `g102' = `g16'*`g23' - `g16'*`g32' - `g61'*`g23' + `g61'*`g32'
   scalar `g36'  = `g63' + `g101'/`g83' - `g102'/`g83'
   // scalar `g36' - `g63' = ((`g13' - `g31')*(`g26' - `g62') - (`g16'
- `g61')*(`g23' - `g32'))/(`g12' - `g21'))

   tempname g111  g112
   scalar `g111' = `g14'*`g25' - `g14'*`g52' - `g41'*`g25' + `g41'*`g52'
   scalar `g112' = `g15'*`g24' - `g15'*`g42' - `g51'*`g24' + `g51'*`g42'
   scalar `g45'  = `g54' + `g111'/`g83' - `g112'/`g83'
   // scalar `g45' - `g54' = ((`g14' - `g41')*(`g25' - `g52') - (`g15'
- `g51')*(`g24' - `g42'))/(`g12' - `g21'))

   tempname g121  g122
   scalar `g121' = `g14'*`g26' - `g14'*`g62' - `g41'*`g26' + `g41'*`g62'
   scalar `g122' = `g16'*`g24' - `g16'*`g42' - `g61'*`g24' + `g61'*`g42'
   scalar `g46' = `g64' + `g121'/`g83' - `g122'/`g83'
   // scalar `g46' - `g64' = ((`g14' - `g41')*(`g26' - `g62') - (`g16'
- `g61')*(`g24' - `g42'))/(`g12' - `g21'))

   tempname g131  g132
   scalar `g131' = `g15'*`g26' - `g15'*`g62' - `g51'*`g26' + `g51'*`g62'
   scalar `g132' = `g16'*`g25' - `g16'*`g52' - `g61'*`g25' + `g61'*`g52'
   scalar `g46' = `g64' + `g131'/`g83' - `g132'/`g83'
   // scalar `g56' - `g65' = ((`g15' - `g51')*(`g26' - `g62') - (`g16'
- `g61')*(`g25' - `g52'))/(`g12' - `g21'))


	tempname l1 l2 l3 l4 l5 l6 l7
	scalar `l1' = `at'[1,55]
	scalar `l2' = `at'[1,56]
	scalar `l3' = `at'[1,57]
	scalar `l4' = `at'[1,58]
	scalar `l5' = `at'[1,59]
	scalar `l6' = `at'[1,60]
	scalar `l7' = -`l1' - `l2' - `l3' -`l4' - `l5' - `l6'
	
	
	// Outras Variáveis demográficas
	
	// ano
	tempname f1 f2 f3 f4 f5 f6 f7
	scalar `f1' = `at'[1,61]
	scalar `f2' = `at'[1,62]
	scalar `f3' = `at'[1,63]
	scalar `f4' = `at'[1,64]
	scalar `f5' = `at'[1,65]
	scalar `f6' = `at'[1,66]
	scalar `f7' = -`f1' - `f2' - `f3' -`f4' - `f5' - `f6'
	
	// agechef
	tempname z1 z2 z3 z4 z5 z6 z7
	scalar `z1' = `at'[1,67]
	scalar `z2' = `at'[1,68]
	scalar `z3' = `at'[1,69]
	scalar `z4' = `at'[1,70]
	scalar `z5' = `at'[1,71]
	scalar `z6' = `at'[1,72]
	scalar `z7' = -`z1' - `z2' - `z3' -`z4' - `z5' - `z6'
	
	// escchef
	tempname t1 t2 t3 t4 t5 t6 t7
	scalar `t1' = `at'[1,73]
	scalar `t2' = `at'[1,74]
	scalar `t3' = `at'[1,75]
	scalar `t4' = `at'[1,76]
	scalar `t5' = `at'[1,77]
	scalar `t6' = `at'[1,78]
	scalar `t7' = -`t1' - `t2' - `t3' -`t4' - `t5' - `t6'
	
	
	// respropria
	tempname r1 r2 r3 r4 r5 r6 r7
	scalar `r1' = `at'[1,79]
	scalar `r2' = `at'[1,80]
	scalar `r3' = `at'[1,81]
	scalar `r4' = `at'[1,82]
	scalar `r5' = `at'[1,83]
	scalar `r6' = `at'[1,84]
	scalar `r7' = -`r1' - `r2' - `r3' -`r4' - `r5' - `r6'
	
	// resid
	tempname v1 v2 v3 v4 v5 v6 v7
	scalar `v1' = `at'[1,85]
	scalar `v2' = `at'[1,86]
	scalar `v3' = `at'[1,87]
	scalar `v4' = `at'[1,88]
	scalar `v5' = `at'[1,89]
	scalar `v6' = `at'[1,90]
	scalar `v7' = -`v1' - `v2' - `v3' -`v4' - `v5' - `v6'
	
	// residsq
	tempname e1 e2 e3 e4 e5 e6 e7
	scalar `e1' = `at'[1,91]
	scalar `e2' = `at'[1,92]
	scalar `e3' = `at'[1,93]
	scalar `e4' = `at'[1,94]
	scalar `e5' = `at'[1,95]
	scalar `e6' = `at'[1,96]
	scalar `e7' = -`e1' - `e2' - `e3' -`e4' - `e5' - `e6'
	
	
	// Okay, now that we have all the parameters, we can
	// calculate the expenditure shares.	
	quietly {
		// First get the price index
		// I set a_0 = 5
		tempvar lnpindex
		gen double `lnpindex' = 5 + `a1'*`lnp1' + `a2'*`lnp2'	///
					  + `a3'*`lnp3' + `a4'*`lnp4' + `a5'*`lnp5' + `a6'*`lnp6' + `a7'*`lnp7'
		forvalues i = 1/7 {
			forvalues j = 1/7 {
				replace `lnpindex' = `lnpindex' + 	///
					0.5*`g`i'`j''*`lnp`i''*`lnp`j''
			}
		}
		
		// The b(p) term in the QUAIDS model:
		tempvar bofp
		gen double `bofp' = 0
		forvalues i = 1/7 {
			replace `bofp' = `bofp' + `lnp`i''*`b`i''
		}
		replace `bofp' = exp(`bofp')
		
		
		// Finally, the expenditure shares for 6 of the 7
		// goods (the fourth is dropped to avoid singularity)
		replace `w1' = `a1' + `g11'*`lnp1' + `g12'*`lnp2' +	///
				      `g13'*`lnp3' + `g14'*`lnp4' +	`g15'*`lnp5' + `g16'*`lnp6' +
`g17'*`lnp7' + ///
				      `b1'*(`lnm' - `lnpindex') + `f1'*`ano' + `z1'*`agechef' +
`t1'*`escchef' + `r1'*`respropria'	+ ///
				      `v1'*`resid' + `e1'*`residsq' + `l1'/`bofp'*(`lnm' -
`lnpindex')^2
		replace `w2' = `a2' + `g21'*`lnp1' + `g22'*`lnp2' +	///
				      `g23'*`lnp3' + `g24'*`lnp4' +	`g25'*`lnp5' + `g26'*`lnp6' +
`g27'*`lnp7' + ///
				      `b2'*(`lnm' - `lnpindex') + `f2'*`ano' + `z2'*`agechef' +
`t2'*`escchef' + `r2'*`respropria'	+ ///
				      `v2'*`resid' + `e2'*`residsq' + `l2'/`bofp'*(`lnm' -
`lnpindex')^2
		replace `w3' = `a3' + `g31'*`lnp1' + `g32'*`lnp2' +	///
				      `g33'*`lnp3' + `g34'*`lnp4' +	`g35'*`lnp5' + `g36'*`lnp6' +
`g37'*`lnp7' + ///
				      `b3'*(`lnm' - `lnpindex') + `f3'*`ano' + `z3'*`agechef' +
`t3'*`escchef' + `r3'*`respropria'	+ ///
				      `v3'*`resid' + `e3'*`residsq' + `l3'/`bofp'*(`lnm' -
`lnpindex')^2
		replace `w4' = `a4' + `g41'*`lnp1' + `g42'*`lnp2' +	///
				      `g43'*`lnp3' + `g44'*`lnp4' +	`g45'*`lnp5' + `g46'*`lnp6' +
`g47'*`lnp7' + ///
				      `b4'*(`lnm' - `lnpindex') + `f4'*`ano' + `z4'*`agechef' +
`t4'*`escchef' + `r4'*`respropria'	+ ///
				      `v4'*`resid' + `e4'*`residsq' + `l4'/`bofp'*(`lnm' -
`lnpindex')^2
		replace `w5' = `a5' + `g51'*`lnp1' + `g52'*`lnp2' +	///
				      `g53'*`lnp3' + `g54'*`lnp4' +	`g55'*`lnp5' + `g56'*`lnp6' +
`g57'*`lnp7' + ///
				      `b5'*(`lnm' - `lnpindex') + `f5'*`ano' + `z5'*`agechef' +
`t5'*`escchef' + `r5'*`respropria'	+ ///
				      `v5'*`resid' + `e5'*`residsq' + `l5'/`bofp'*(`lnm' -
`lnpindex')^2
		replace `w6' = `a6' + `g61'*`lnp1' + `g62'*`lnp2' +	///
				      `g63'*`lnp3' + `g64'*`lnp4' +	`g65'*`lnp5' + `g66'*`lnp6' +
`g67'*`lnp7' + ///
				      `b6'*(`lnm' - `lnpindex') + `f6'*`ano' + `z6'*`agechef' +
`t6'*`escchef' + `r6'*`respropria'	+ ///
				      `v6'*`resid' + `e6'*`residsq' + `l6'/`bofp'*(`lnm' -
`lnpindex')^2
	}
	
end


Thank you very much in advance.
Best regards,
Ana.




2011/7/18 Brian P. Poi <[email protected]>:
>
> On 07/18/2011 06:40 PM, Ana wrote:
>>
>> Dear Statalisters (and Brian Poi),
>>
>> I'm using nlsur Quaids from Brian Poi (2008).
>> My routine is (the same as Poi's one):
>>
>> nlsur quaids @ w1 w2 w3 lnp1-lnp4 lnexp, ifgnls nequations(3) param(a1
>> a2 a3 b1 b2 b3 g11 g12 g13 g22 g23 g33 l1 l2 l3) nolog
>>
>> I'm trying to compare two models: unrestricted model and restricted model.
>> My restriction is something like this: `g22' = `g12'*`g13'
>>
>> The problem is that I'm getting r(198) error when I run the restricted
>> model.
>> The only thing that I include in the original model is:
>>
>> tempname `g22'
>> scalar `g22' = `g12'*`g13'
>>
>> The mistakes is clearly a syntax one (problably the multiplication is
>> not correct).
>>
>> Can anyone help me?
>> I really appreciate it.
>>
>
> There are two issues I see here.  One,
>
> .  tempname `g22'
>
> should be
>
> .  tempname g22       (without `' ticks)
>
> because you are declaring a new temporary scalar.
>
> The other is that since you are constraining g22, it is no longer a separate
> parameter to be estimated, so you shouldn't declare it in your -nlsur-
> statement:
>
> . nlsur quaids @ w1 w2 w3 lnp1-lnp4 lnexp, ifgnls nequations(3) ///
>   param(a1 a2 a3 b1 b2 b3 g11 g12 g13 g23 g33 l1 l2 l3) nolog
>
>                                      ^ (I took out g22)
>
> If you have other parameter restrictions like that one, then you'll want to
> take them out of the param() option, too.
>
> Out of curiosity, where does the restriction g22 = g12*g13 come from?
>
>   -- Brian Poi
>   -- [email protected]
>
>
> *
> *   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