Ncik - no, not that. i was not concise enough in my description of what I was thinking!
i am looking for an on-the-fly variable creation.
my "var1<=60" evaluates to 0 or 1 depending on the value of var1. likewise for var2. thus the tab statement that i envisioned would yield a 2x2 table
in the ccode below, i generated two indicator variables var160 and var170 to demonstrate the desired effect. this particular example takes 3 lines of code to tabulate, but more complex conidtions would require more.
i envision a way to generate the indicator variables on the fly.
more generally, the temporary varibel need not be an indicator variable.
the syntax engine would evaluate expressions and create a temporary variable from the expression.
example:
thanks
this would regress y against x1, x2, an indicator for x3<=5, and the value of 1/x4
i am looking for an on-the-fly variable creation.
my "var1<=60" evaluates to 0 or 1 depending on the value of var1. likewise for var2. thus the tab statement that i envisioned would yield a 2x2 table
in the ccode below, i generated two indicator variables var160 and var170 to demonstrate the desired effect. this particular example takes 3 lines of code to tabulate, but more complex conidtions would require more.
Code:
input var1 var2 var1 var2 1. 10 10 2. 20 20 3. 30 30 4. 40 40 5. 50 50 6. 60 60 7. 70 70 8. 80 80 9. 90 90 10. 10 90 11. 20 80 12. 30 70 13. 40 60 14. 50 50 15. 60 40 16. 30 70 17. 20 80 18. 10 90 19. end . tab var1 var2 if var1<=60 & var2<=70 | var2 var1 | 10 20 30 40 50 60 70 | Total -----------+-----------------------------------------------------------------------------+---------- 10 | 1 0 0 0 0 0 0 | 1 20 | 0 1 0 0 0 0 0 | 1 30 | 0 0 1 0 0 0 2 | 3 40 | 0 0 0 1 0 1 0 | 2 50 | 0 0 0 0 2 0 0 | 2 60 | 0 0 0 1 0 1 0 | 2 -----------+-----------------------------------------------------------------------------+---------- Total | 1 1 1 2 2 2 2 | 11 . def var160 = var1<=60 . def var270 = var2<=70 . tab var160 var270 | var270 var160 | 0 1 | Total -----------+----------------------+---------- 0 | 2 1 | 3 1 | 4 11 | 15 -----------+----------------------+---------- Total | 6 12 | 18 .
more generally, the temporary varibel need not be an indicator variable.
the syntax engine would evaluate expressions and create a temporary variable from the expression.
example:
Code:
reg y x1 x2 {x3<=5} {1/x4}
this would regress y against x1, x2, an indicator for x3<=5, and the value of 1/x4
Comment