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: Running a model using global macro statement


From   Sam Asin <[email protected]>
To   [email protected]
Subject   Re: st: Running a model using global macro statement
Date   Tue, 3 Sep 2013 13:56:19 -0400

Thanks for your prompt, helpful responses!  I was wondering if it was
an issue with the quotes and spaces, but for whatever reason, the
spaces aren't automatically being input correctly.  Here is a snippet
from the do file:

                *Ken Parameters (Commented out means probably will
never be used, see below line for actual specification for model)
	global dage "dage1-dage8"
	global cohorts "cohort96 cohort97 cohort98 cohort99 cohort00 cohort01
cohort02 cohort03 cohort04 cohort05 cohort06 cohort07 cohort08"
	global standard " second_lien metro units condo"
	global oltv "ltv1 ltv2 ltv3 ltv4 ltv5"
	global ofico "fico1 fico2 fico3 fico4"
//	global interx "x_fico_ltv_dti"
//	global refib "yt*"
	global fc "xfc11 xfc12 xfc13 xfc14 xfc21 xfc22 xfc23 xfc24 xfc31
xfc32 xfc33 xfc34 xfc41 xfc42 xfc43 xfc44"
	global fdp "fico_ltv_11 fico_ltv_12 fico_ltv_13 fico_ltv_14
fico_ltv_15 fico_ltv_21 fico_ltv_22 fico_ltv_23 fico_ltv_24
fico_ltv_25 fico_ltv_31 fico_ltv_32 fico_ltv_33 fico_ltv_34
fico_ltv_35 fico_ltv_41 fico_ltv_42 fico_ltv_43 fico_ltv_44
fico_ltv_45"
	global oupb "oupb1-oupb4"
	global sato "sato1-sato2"
//	global census "st_midatlantic st_eastnorcent st_westnorcent
st_eastsocent st_westsocent st_mountain st_pacific st_newengland"
//	global rule "st_rule2-st_rule4"
	global dti "fdti1 fdti2 fdti3 fdti4 bdti1 bdti2 bdti3 bdti4"

********************************* KEN PARAMETER CHOICE ************************
**********                                                          ***********
global kenparam $dage $cohorts $oltv $ofico $fc $oupb $dti $sato $standard




global zipind "i.zipspecial"
	global zipindproportion .25

global dateind "i.date"
global regtype "mlogit eventmulti"
global dependentvar "90"

global regressionstatement "$regtype" "$dependentvar" " collection2 "
"$zipind" "$dateind" "$kenparam" "$ifstatement" ", " "$options"



and the snippet from the command window:


. global regressionstatement "$regtype" "$dependentvar" " collection2
" "$zipind" "$dateind" "$kenparam" "$ifstatement" ", " "$options"



. display "$regressionstatement"
mlogit eventmulti90 collection2 i.zipspeciali.datedage1-dage8 cohort96
cohort97 cohort98 cohort99 cohort00 cohort01 cohort02 cohort03 coh
> ort04 cohort05 cohort06 cohort07 cohort08 ltv1 ltv2 ltv3 ltv4 ltv5 fico1 fico2 fico3 fico4 xfc11 xfc12 xfc13 xfc14 xfc21 xfc22 xfc23 xf
> c24 xfc31 xfc32 xfc33 xfc34 xfc41 xfc42 xfc43 xfc44 oupb1-oupb4 fdti1 fdti2 fdti3 fdti4 bdti1 bdti2 bdti3 bdti4 sato1-sato2  second_lie
> n metro units condoif def_obs_count<2, constant tolerance(1e-8)

Note that I had to put spaces around "collection2" in the macro to
make it show up correctly, and the i.zipspecial and i.date variables
are still messed up.  This is all odd, because above I defined
$kenparam in the manner that you specified and had no need to add
spaces, but for some reason on $regressionstatement I need to add
spaces.

Thanks,

Sam



On Tue, Sep 3, 2013 at 11:16 AM, Eric A. Booth <[email protected]> wrote:
> <>
>
> Apologies, I hit 'send' early on my last email.... the last point was
> showing how your model runs once you strip away the double compound
> quotes, consider:
>
>
>  global regtype logit
>  global dependentvar event90
>  global collection2 i.zipspecial i.date
>  global zipind dage1-dage8
>
> global regressionstatement "$regtype" "$dependentvar" " "
> "collection2" " " "$zipind" " "
> di "${regressionstatement}" // versus:
> di `"${regressionstatement}"'
> *! this is not what you want.
>
> ****instead try this
> global regressionstatement  $regtype $dependentvar $collection2 $zipind
>
> di `"${regressionstatement}"'
> ${regressionstatement} //this works.
>
>
> - Eric
>
>
> On Tue, Sep 3, 2013 at 10:13 AM, Eric A. Booth <[email protected]> wrote:
>> <>
>> This a issue with the quotes. Your global regressionstatement doesnt
>> need all those quotes around the globals, nor the extra set of quotes
>> to embed spaces.  First, you should read the -help quotes- file about
>> double compound quotes because it's useful anytime you are working
>> with macros that contain multiple quotes or nested quotes as you are
>> attempting to do.  But in this case the issue is that you just do not
>> need quotes at all.  Nesting your globals in the
>> ${regressionstatement} without quotes will insert the proper spaces.
>>
>> So
>>
>>
>>
>>
>> On Tue, Sep 3, 2013 at 9:45 AM, Sam Asin <[email protected]> wrote:
>>> Hello, this is my first post here!
>>>
>>> I am trying to create a do file that runs a logit command.  I use a
>>> global macro statement to set up the regression, it's called
>>> $regressionstatement.
>>>
>>> global regressionstatement "$regtype" "$dependentvar" " "
>>> "collection2" " " "$zipind" " " "$dateind" " " "$kenparam"
>>> "$ifstatement" ", " "$options"
>>>
>>>
>>>
>>> At the bottom of my code, it invokes $regressionstatement.  However, I
>>> get this error:
>>>
>>> 2" " invalid name
>>> r(198);
>>>
>>>
>>>
>>> However, if I write:
>>>
>>> display "$regressionstatement"
>>>
>>>
>>> and then copy paste the output onto my command line and run it, it
>>> works.  I also tried:
>>>
>>> "$regressionstatement"
>>>
>>> to no avail, as well as:
>>>
>>> global test "$regressionstatement"
>>>
>>> $test
>>>
>>> How can I make my code run the regressoin statement that I've made
>>> without requiring the additional manual input?  For what it's worth,
>>> I've included the code of interest below.
>>>
>>>
>>>
>>>
>>> global regressionstatement "$regtype" "$dependentvar" " "
>>> "collection2" " " "$zipind" " " "$dateind" " " "$kenparam"
>>> "$ifstatement" ", " "$options"
>>>
>>>  display "$regressionstatement"
>>> logit event90 collection2 i.zipspecial i.date dage1-dage8 cohort96
>>> cohort97 cohort98 cohort99 cohort00 cohort01 cohort02 cohort03
>>> cohort04 cohort05 cohort06 cohort0
>>>> 7 cohort08 ltv1 ltv2 ltv3 ltv4 ltv5 fico1 fico2 fico3 fico4 xfc11 xfc12 xfc13 xfc14 xfc21 xfc22 xfc23 xfc24 xfc31 xfc32 xfc33 xfc34 xfc41 xfc42 xfc43 xfc44 oupb1-
>>>> oupb4 fdti1 fdti2 fdti3 fdti4 bdti1 bdti2 bdti3 bdti4 sato1-sato2  second_lien metro units condo if def_obs_count<2, vce(robust)
>>> .
>>> $regressionstatement
>>> 2" " invalid name
>>> logit event90 collection2 i.zipspecial i.date dage1-dage8 cohort96
>>> cohort97 cohort98 cohort99 cohort00 cohort01 cohort02 cohort03
>>> cohort04 cohort05 cohort06 cohor
>>>> t07 cohort08 ltv1 ltv2 ltv3 ltv4 ltv5 fico1 fico2 fico3 fico4 xfc11 xfc12 xfc13 xfc14 xfc21 xfc22 xfc23 xfc24 xfc31 xfc32 xfc33 xfc34 xfc41 xfc42 xfc43 xfc44 oupb
>>>> 1-oupb4 fdti1 fdti2 fdti3 fdti4 bdti1 bdti2 bdti3 bdti4 sato1-sato2  second_lien metro units condo if def_obs_count<2, vce(robust)
>>> note: 33890.zipspecial != 0 predicts success perfectly
>>>       33890.zipspecial dropped and 60 obs not used
>>>
>>> etc.
>>>
>>>
>>> Thanks!
>>>
>>> Sam
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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