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
Multiple imputation when there is a certain group that did not answer a certain questionHello Statalist, I have a general question about multiple imputations method in Stata. There are mu…
Reshaping multiple variables at onceHi All, I have data that resembles the following: Code: * Example generated by -dataex-. To insta…
Hausman Test producing different resultsI am using panel data and trying to decide between the fixed and random effects models to use. When…
different 'Beta' values in the same Effect coding in regressionI have entered a categorial variable (country) to a regression and I coded their values in Effect co…
Collapse by what?Hi everyone, I have the following database which I describe quickly. Basically it is a escalation o…
Subscribe to:
Post Comments (Atom)
0 Response to create new value based on variable name
Post a Comment