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
Variable types for regressionsCan anybody let me know what are the variable types on which a regression can run? …
Obtaining marginal effects for all possible predictsHi everyone, I was wondering to know how can I combine the below four margins commands in a single o…
Extracting Year From DateHi, I have looked through older discussions and applied suggestions but my code returns an empty var…
DOS windows how to remove itDear all, My question will be quite simple I think but I just need to know if my wish could be real…
GEE: results significant only with independent and exchangeable correlation structureHello there! I am trying to fit a GEE Poisson model on a panel dataset consisting of T=360 and N=30…
Subscribe to:
Post Comments (Atom)
0 Response to Multiple if conditions within loop
Post a Comment