Hi all,
I have a dataset with variable names from taxdebt_20120101 to taxdebt_20131231 with the last digits being a date format. Those variables display values from 0 - 100,000
I am trying to create a new variable that equals the date of the variable name if the value of that variable is > 0.
My code so far:
gen date = .
forval j = 20120101/20131231 {
replace date = `j' if taxdebt_`j' > 0
}
tostring date, replace format(%20.0f)
gen date2 = date(date,"YMD")
format date2 %td
Unfortunately the code doesn't quite work. I keep getting the date 20120132. A date is also displayed for values = 0.
Hope you can help.
Related Posts with create new value based on variable name
couting unique observation id sales profit year size_group a 36 9 1991 1 a 48 17 1992 1 a 25 7 1993 2 b 65 18 19…
Modelling longitudinal dataHello members, pleaseRegression for follow-up studies i have a data on follow up study, data was col…
Minimum distance function / Stochastic Frontier AnalysisHi there: Does anyone know how to estimate a minimum distance function in Stata? I have the paramete…
Calculating month between two datesDear All, May data set contains a variable named month1 for the first month and year1 for the first …
Modelling dose with multiple balancing score. Imbens (2000)Good day statlisters , please I am interested in applying propensity using modelling dose of treatme…
Subscribe to:
Post Comments (Atom)
0 Response to create new value based on variable name
Post a Comment