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
Omitted variables in results using OLS modelDear All, I am analyzing data household level data and have included 10 provinces. I have also cate…
Contingent Valuation MethodHi! I am trying to make a study in regards to contingent valuation method using logit, which is in m…
Graph with mean attendance and variation in attendance to several training sessions, split by groupsDear Statalisters, I would love it if someone could help me solve the issue below. I try to give as…
Harrell's C stat after multiple imputationDear all, I am having problems figuring out how to calculate Harell's C-stat following stcox on imp…
When operate RIF-QR, does the command 'rifhdreg' contain a Gaussian kernel distribution?Generally, the Gaussian kernel distribution is recommended for RIF quantile regression. When I use …
Subscribe to:
Post Comments (Atom)
0 Response to Multiple if conditions within loop
Post a Comment