mercredi 3 août 2016

Stata: Hardcoded and optional [if] statements in program using syntax

I'm learning how to use the optional syntax when writing simple stata programs and I'm wondering if it's possible to hardcode if statements while at the same time passing optional [if] statements through the syntax options.

Let me try to explain. I know that a a simple function can be written like:

sysuse auto

program meanprice
    syntax [if]

    mean price `if'
end 

and then I can for example use some optional if statements like:

meanprice if price > 6000 & rep78 > 2

However, lets say I want to hardcore the price > 6000 statement and still be able to selectively choose optional if statements (the reason I want to do this is that the part I want to hardcode is very rigorous and I always want to pass these options through some nested programs that I'm writing without having to specify them each time)

I have tried using e.g.,

program meanprice_test
    syntax [if]

    mean price if price > 6000 `if'
end 

but this does clearly not work (to my understanding because `syntax' is parsing text/strings?)

Is there any simple way to achieve the desired outcome using syntax and [if]? I can think of some very tedious workarounds that I'd rather avoid.

Thanks in advance,

Billy

Aucun commentaire:

Enregistrer un commentaire