![Statalist](/includes/images/head_statalist.jpg) |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: A Problem on generating a variable using --appended-dataset
From |
Asgar Khademvatani <[email protected]> |
To |
[email protected] |
Subject |
st: A Problem on generating a variable using --appended-dataset |
Date |
Mon, 19 Nov 2007 02:23:06 -0700 |
Dear All,
Basically, I am estimating a cost model using time series dataset over
1958-2000. Then, I have appended a new observation over 2001-2050 to my
master dataset in the Stata memory, using--append-- command. I want to
generate some new variables defined based on functions upon estimated
coefficient and the other variables, I want generate these variables
only over 2001-2050 during the same period of new using
observation.Actually, I already tried --gen-- command but it only
generate the variables over master dataset period over 1958-2000 NOT
over 2001-2050. In doing so, I am going to write a --forvalues-- loop to
do so. But the variables only are generated at one single
observation,say only 2001, and it is re-extended over other years with
the same values . For example, my written loop and the stata results are
given as:
A Sample Loop:
forvalues i = 44/93 {
gen X = _b[le_sg] + _b[lple_sg]*(plpl_sg[`i']) +
_b[lpme_sg]*(plpm_sg[`i']) + _b[lek_neg_sg]*(plk_sg[`i']) +
_b[let_sg]*(pt[`i'])
list X
}
The Stata Output:
do "C:\DOCUME~1\ASGARK~1\LOCALS~1\Temp\STD0i000000.tmp"
. 1. forvalues i = 44/93 {
2. gen X =_b[le_sg] + _b[lple_sg]*(plpl_sg[`i']) +
_b[lpme_sg]*(plpm_sg[`i']) + _b[lek_neg_sg]*(plk
> _sg[`i']) + _b[let_sg]*(pt[`i'])
3. list X
4. }
44
+-----------+
| X
|-----------|
1. | -7.730469 |
2. | -7.730469 |
3. | -7.730469 |
4. | -7.730469 |
5. | -7.730469 |
|-----------|
6. | -7.730469 |
7. | -7.730469 |
8. | -7.730469 |
9. | -7.730469 |
10. | -7.730469 |
|-----------|
11. | -7.730469 |
12. | -7.730469 |
13. | -7.730469 |
14. | -7.730469 |
15. | -7.730469 |
|-----------|
16. | -7.730469 |
17. | -7.730469 |
18. | -7.730469 |
19. | -7.730469 |
20. | -7.730469 |
|-----------|
21. | -7.730469 |
22. | -7.730469 |
23. | -7.730469 |
24. | -7.730469 |
25. | -7.730469 |
|-----------|
26. | -7.730469 |
27. | -7.730469 |
28. | -7.730469 |
29. | -7.730469 |
30. | -7.730469 |
|-----------|
31. | -7.730469 |
32. | -7.730469 |
33. | -7.730469 |
34. | -7.730469 |
35. | -7.730469 |
|-----------|
36. | -7.730469 |
37. | -7.730469 |
38. | -7.730469 |
39. | -7.730469 |
40. | -7.730469 |
|-----------|
41. | -7.730469 |
42. | -7.730469 |
43. | -7.730469 |
44. | -7.730469 |
45. | -7.730469 |
|-----------|
46. | -7.730469 |
47. | -7.730469 |
48. | -7.730469 |
49. | -7.730469 |
50. | -7.730469 |
|-----------|
51. | -7.730469 |
52. | -7.730469 |
53. | -7.730469 |
54. | -7.730469 |
55. | -7.730469 |
|-----------|
56. | -7.730469 |
57. | -7.730469 |
58. | -7.730469 |
59. | -7.730469 |
60. | -7.730469 |
|-----------|
61. | -7.730469 |
62. | -7.730469 |
63. | -7.730469 |
64. | -7.730469 |
65. | -7.730469 |
|-----------|
66. | -7.730469 |
67. | -7.730469 |
68. | -7.730469 |
69. | -7.730469 |
70. | -7.730469 |
|-----------|
71. | -7.730469 |
72. | -7.730469 |
73. | -7.730469 |
74. | -7.730469 |
75. | -7.730469 |
|-----------|
76. | -7.730469 |
77. | -7.730469 |
78. | -7.730469 |
79. | -7.730469 |
80. | -7.730469 |
|-----------|
81. | -7.730469 |
82. | -7.730469 |
83. | -7.730469 |
84. | -7.730469 |
85. | -7.730469 |
|-----------|
86. | -7.730469 |
87. | -7.730469 |
88. | -7.730469 |
89. | -7.730469 |
90. | -7.730469 |
|-----------|
91. | -7.730469 |
92. | -7.730469 |
93. | -7.730469 |
94. | -7.730469 |
+-----------+
X already defined
r(110);
end of do-file
As you see in the above, X variable is generated only in 2001 and it is
repeated over next years with the same value. I am not sure what is
wrong with my loop. May somebody please help me out on this matter and
tell me what is wrong with that? Otherwise, I am just wondering that is
there another way other than writing a loop for generating the variables
over 2001-2050?
Thank you in advance for any help.
Asgar Kh.
University of Calgary-Canada
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/