Dear Stata users,
I have an unbalanced panel dataset where I tag all lags for each firm/year pair (variables nLags in the code), which I use to generate a new variable whose value depends on the specific values of each lags. The problem is that I don't know how to specify the multiple if conditions since the number of conditions depend on the number of lags. For example, if the firm has 3 lags, I have to check that L1.gas==0, L2.gas==0 and L3.gas==0. If the firm only has one lag, I only want to check that L1.gas==0 and so on.
In the following code example, 7 is the maximum possible number of lags.
forvalues i = 1/7 {
replace fuelswitch_togas= 1 if gas > 0 & L1.gas-L`i'.gas == 0 & nLags == `i'
}
Thanks for your help,
Emmanuel Murray Leclair
Related Posts with Multiple if conditions within loop
Using quarterly() to generate date from string.I'm running Stata/SE 15.1 (updated 27/08/19) on MacOS 10.13.5 I would like to convert string data t…
help with 3 level meglmHi, I want to look at factors that predict outcome (ordered 0-4). The factors I want to look at are…
Count function with bysortHello. I'm currently working on the stock market. I have thousands of stocks and their daily returns…
dydx() margins 'not estimable'Hello all I'm doing a difference-in-difference regression with 3 time points (1 pre, and 2 post). M…
IPFraking - How to account for population totals?Hello, I am very new to Stata, so please bear with me.....I would like to adjust my sample to the p…
Subscribe to:
Post Comments (Atom)
0 Response to Multiple if conditions within loop
Post a Comment