Dear all,
From the variable v I would like to generate 3 variables: v1, v2, v3. Given that these are the 3 observations of v. I need to make separate calculations with them, therefore I need to cut this variable as many times as its observations. Of course I can write:
gen v1 = v[1]
gen v2 = v[2]
gen v3 = v[3]
although I have more that 3 and therefore I look for a proper loop, I have tried the following:
forvalues i = 1/_n {
gen v`i'= v[_n-`i']
}
but it has a syntax error that I cannot fix. Generally whenever I enter `i' inside brackets in such commands I get an error. Could anyone suggest a solution or a different loop that I can use?
Thanks is advance,
Shadi
Related Posts with generating separate variables from one variables's observations, is there a loop?
Variable ProblemHi, everybody, How can I change observations with non-numerical content? I have a variable that is n…
Clustering Standard errors at industry versus company levelDear Statalist members I am running a regression with Log stock returns on 1st quarter of 2020 as my…
How to extract month from an iso date?I have a date in the following iso format: ISODATE 2017-09-01 10:43:04.000 The format is Stata is:…
Missing ValuesHello, everybody. There is a way to apply: drop if missing(var) when you have more than one variabl…
Cleaning DataHello, everybody. I've got numerical variables, but where some observations are "1oooo" "150 kg for…
Subscribe to:
Post Comments (Atom)
0 Response to generating separate variables from one variables's observations, is there a loop?
Post a Comment