LSMS_Library 0.2.9.dev0__py3-none-any.whl → 0.2.10.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. lsms_library/__init__.py +7 -0
  2. lsms_library/countries/Bosnia-Herzegovina/2003/Data/cbh_ind_weighs.dta.dvc +5 -0
  3. lsms_library/countries/Bosnia-Herzegovina/2003/Data/cbhcfhh.dta.dvc +5 -0
  4. lsms_library/countries/Bosnia-Herzegovina/2003/Data/cbhcfind.dta.dvc +5 -0
  5. lsms_library/countries/Bosnia-Herzegovina/2003/Data/cbhhhpos.dta.dvc +5 -0
  6. lsms_library/countries/Bosnia-Herzegovina/2003/Data/cbhihh.dta.dvc +5 -0
  7. lsms_library/countries/Bosnia-Herzegovina/2003/Data/cbhiind.dta.dvc +5 -0
  8. lsms_library/countries/Bosnia-Herzegovina/2003/Data/cbhjhist.dta.dvc +5 -0
  9. lsms_library/countries/China/1995-97/_/data_info.yml +28 -0
  10. lsms_library/countries/China/_/data_scheme.yml +9 -0
  11. lsms_library/countries/India/1997-98/_/data_info.yml +29 -0
  12. lsms_library/countries/India/1997-98/_/testing.py +9 -0
  13. lsms_library/countries/India/_/data_scheme.yml +13 -0
  14. lsms_library/countries/Iraq/2006-07/_/data_info.yml +13 -0
  15. lsms_library/countries/Iraq/2012/_/data_info.yml +13 -0
  16. lsms_library/countries/Iraq/_/data_scheme.yml +8 -0
  17. lsms_library/countries/Kosovo/2000/_/data_info.yml +14 -0
  18. lsms_library/countries/Kosovo/_/data_scheme.yml +9 -0
  19. lsms_library/countries/Liberia/2018-19/_/data_info.yml +13 -0
  20. lsms_library/countries/Liberia/_/data_scheme.yml +8 -0
  21. lsms_library/countries/Nigeria/_/household_roster.py +0 -2
  22. lsms_library/countries/Serbia/2007/_/data_info.yml +13 -0
  23. lsms_library/countries/Serbia/_/data_scheme.yml +8 -0
  24. lsms_library/countries/Serbia and Montenegro/2002/_/data_info.yml +13 -0
  25. lsms_library/countries/Serbia and Montenegro/2003/_/data_info.yml +13 -0
  26. lsms_library/countries/Serbia and Montenegro/_/data_scheme.yml +8 -0
  27. lsms_library/countries/South Africa/1993/_/data_info.yml +34 -0
  28. lsms_library/countries/South Africa/_/data_scheme.yml +8 -0
  29. lsms_library/countries/Timor-Leste/2007-08/_/data_info.yml +13 -0
  30. lsms_library/countries/Timor-Leste/_/data_scheme.yml +8 -0
  31. lsms_library/countries/Togo/2018/_/data_info.yml +13 -0
  32. lsms_library/countries/Togo/_/data_scheme.yml +8 -0
  33. lsms_library/countries/Uganda/2005-06/_/data_info.yml +11 -0
  34. lsms_library/countries/Uganda/2009-10/_/data_info.yml +10 -0
  35. lsms_library/countries/Uganda/_/data_scheme.yml +6 -0
  36. lsms_library-0.2.10.dev0.dist-info/METADATA +290 -0
  37. {lsms_library-0.2.9.dev0.dist-info → lsms_library-0.2.10.dev0.dist-info}/RECORD +39 -10
  38. lsms_library/contributing.org +0 -290
  39. lsms_library-0.2.9.dev0.dist-info/METADATA +0 -138
  40. {lsms_library-0.2.9.dev0.dist-info → lsms_library-0.2.10.dev0.dist-info}/LICENSE.txt +0 -0
  41. {lsms_library-0.2.9.dev0.dist-info → lsms_library-0.2.10.dev0.dist-info}/WHEEL +0 -0
@@ -1,290 +0,0 @@
1
-
2
- * YAML File Development Instructions for LSMS Package
3
-
4
- This guide explains how to organize ~data_scheme.yml~, ~data_info.yml~, and optional Python transformation scripts to ensure proper functionality of the LSMS package.
5
- Maintaining correct indentation and formatting in ~data_info.yml~ is essential for the file to be processed correctly.
6
-
7
- * 1. Create the _/ Subdirectory and data_scheme.yml
8
-
9
- In each *country directory*, create a subdirectory named _:
10
-
11
- #+begin_src sh
12
- mkdir Mali/_
13
- #+end_src
14
-
15
- Inside the _/ folder, create a ~data_scheme.yml~ file to define the data structure and index for each table:
16
-
17
- #+begin_src yaml
18
- # Mali/_/data_scheme.yml
19
-
20
- Country: Mali
21
-
22
- Data Scheme:
23
- cluster_features:
24
- index: (t, v)
25
- Region: str
26
- Rural: str
27
-
28
- household_roster:
29
- index: (t, v, i, pid)
30
- Sex: str
31
- Age: int
32
- Relationship: str
33
-
34
- individual_education:
35
- index: (t, v, i, pid)
36
- Highest Education: str
37
-
38
- food_acquired:
39
- index: (t, v, visit, i, j, u)
40
- Quantity: float
41
- Price: float
42
- Produced: float
43
-
44
- interview_date:
45
- index: (t, v, visit, i)
46
- Int_t: str
47
-
48
- panel_ids:
49
- index: (t, i)
50
- previous_i: str
51
- #+end_src
52
-
53
- * 2. Create the _/ Subdirectory in Each Wave and Define data_info.yml
54
-
55
- In each *wave directory*, also create an _ folder:
56
-
57
- #+begin_src sh
58
- mkdir Mali/2017-18/_
59
- #+end_src
60
-
61
- Then, inside _/, create a ~data_info.yml~ file to describe the data files and mappings.
62
-
63
- ** 2.1 Basic Format
64
-
65
- #+begin_src yaml
66
- # Mali/2017-18/_/data_info.yml
67
-
68
- cluster_features:
69
- file: ehcvm_conso_mli2018.dta
70
- idxvars:
71
- v: grappe
72
- myvars:
73
- Region: region
74
- Rural: milieu
75
- #+end_src
76
-
77
- ** 2.2 Composite Index or Variables with Functions
78
-
79
- If the variable (e.g., i) requires multiple columns from the original dataset, list them together in a list format, in yml using hyphen (-). For example, if variable i maps to multiple source columns, define it as:
80
- #+begin_src yaml
81
- # Mali/2021-22/_/data_info.yml
82
-
83
- food_acquired:
84
- file: s07b_me_mli2021.dta
85
- idxvars:
86
- v: grappe
87
- visit: vague
88
- i: # Empty row is required here
89
- - grappe
90
- - menage
91
- j: s07bq01
92
- u: s07bq03b
93
- myvars:
94
- ...
95
- #+end_src
96
-
97
- * 3. Apply Transformation Functions in Python
98
- The `format_id` function from local_tools is automatically applied to all index variables by default.
99
-
100
- To apply a different formatting function to a specific index or column variable, you can define your own function and specify it in one of two ways:
101
- • Option 1: Name the function to match the variable name (e.g., i for variable i), and it will be recognized automatically.
102
- • Option 2: Add 'function: function_name' at the end of the mapping list (see bullet 7 for details). This explicitly assigns the function to mappings.
103
-
104
- This approach allows flexible customization of formatting logic for individual variables.
105
- ** 3.1 Wave-Specific Column Transformation
106
-
107
- Create a Python file in the wave’s _ folder, e.g., ~Mali/2017-18/_/2017-18.py~:
108
-
109
- #+begin_src python
110
- # Mali/2017-18/_/2017-18.py
111
-
112
- def i(value):
113
- from lsms_library.local_tools import format_id
114
- return format_id(value[0]) + '0' + format_id(value[1], zeropadding=2)
115
- #+end_src
116
-
117
- ** 3.2 Country-Wide Column Transformation
118
-
119
- To apply a transformation across all waves in a country, define the function in ~Mali/_/mali.py~.
120
-
121
- #+begin_src python
122
- # Mali/_/mali.py
123
-
124
- def i(value):
125
- from lsms_library.local_tools import format_id
126
- return format_id(value[0]) + '0' + format_id(value[1], zeropadding=2)
127
- #+end_src
128
-
129
- * 4. Value Mapping Dictionaries
130
-
131
- Define value mappings in ~data_info.yml~ for categorical variables.
132
-
133
- #+begin_src yaml
134
- # Malawi/2004-05/_/data_info.yml
135
-
136
- myvars:
137
- Rural:
138
- - reside
139
- - # Empty row is required here and the following should be in correct indention
140
- 'Rural': 1 # original_value: mapping_value
141
- 'Urban': 0
142
- #+end_src
143
-
144
- #+begin_src yaml
145
- # Mali/2021-22/_/data_info.yml
146
-
147
- myvars:
148
- in_previous_wave:
149
- - PanelHH
150
- - mapping:
151
- 'Oui': 1 # original_value: mapping_value
152
- 'Non': 0
153
- #+end_src
154
-
155
- Note: The empty line after the variable name is *required* to separate it from the mapping dictionary.
156
-
157
- * 5. Row-Level DataFrame Transformation
158
-
159
- Define a function named after the dataframe in either the wave- or country-level Python file:
160
-
161
- #+begin_src python
162
- # Mali/2021-22/_/2021-22.py
163
-
164
- def panel_ids(df):
165
- from lsms_library.local_tools import format_id
166
- df = df[df['visit'] == '2']
167
- df['previous_i'] = df[['previous_v', 'previous_hid']].apply(
168
- lambda x: format_id(x[0]) + '0' + format_id(x[1], zeropadding=2), axis=1)
169
- return df[['i', 't', 'previous_i']].drop_duplicates().set_index(['i', 't'])
170
- #+end_src
171
-
172
- * 6. Multi-File DataFrames
173
-
174
- ** 6.1 Vertical Merge: Stacking Data Row-Wise (data from multiple files)
175
-
176
- #+begin_src yaml
177
- # Mali/2017-18/_/data_info.yml
178
-
179
- interview_date:
180
- file:
181
- - eaci17_s00p1.dta
182
- - eaci17_s00p2.dta
183
- idxvars:
184
- v: grappe
185
- visit: passage
186
- i:
187
- - grappe
188
- - exploitation
189
- myvars:
190
- Int_t:
191
- - s0q21c
192
- - s0q21b
193
- - s0q21a
194
- converted_categoricals: False
195
- #+end_src
196
-
197
- ** 6.2 File-Specific Overrides
198
-
199
- #+begin_src yaml
200
- # Mali/2014-15/_/data_info.yml
201
- food_acquired:
202
- file:
203
- - EACIALI_p1.dta: #A colon is required here.
204
- Quantity: s13q03a #Override defult Quantity column mapping
205
- - EACIALI_p2.dta
206
- idxvars:
207
- v: grappe
208
- visit: passage
209
- i:
210
- - grappe
211
- - menage
212
- j: s13q01
213
- u: s13q03b
214
- myvars:
215
- Quantity: s13q02
216
- Expenditure: s13q03c
217
- Produced: s13q04a
218
- #+end_src
219
-
220
-
221
- * 7. File-Specific Function Applications
222
- To apply a function to a specific column mapping, add 'function: function_name' at the end of the variable mapping list (as shown in the example for variable i). This function will be applied only to files that use this particular column mapping. If an override mapping is present, the function will not be applied.
223
-
224
- If you want the function to apply across all mappings for column i, refer to bullet point 3, where you can simply define the function name directly after the variable name i.
225
-
226
- #+begin_src yaml
227
- # Malawi/2016-17/_/data_info.yml
228
-
229
- household_roster:
230
- file:
231
- - Cross_Sectional/hh_mod_b.dta
232
- - Panel/hh_mod_b_16.dta:
233
- i: y3_hhid
234
- pid: id_code
235
- idxvars:
236
- i:
237
- - case_id
238
- - mapping: cs_i
239
- pid: pid
240
- myvars:
241
- Sex: hh_b03
242
- Age: hh_b05a
243
- Relation: hh_b04
244
- #+end_src
245
-
246
- src python
247
- # Malawi/2016-17/_/2016-17.py
248
-
249
- def cs_i(value):
250
- from lsms_library.local_tools import format_id
251
- return 'cs-17-' + format_id(value[0])
252
- #+end_src
253
-
254
- * 8. Horizontal Merge = Combining Data Column-Wise (adding columns side by side).
255
-
256
- #+begin_src yaml
257
- # an example
258
- merged_dfs:
259
- dfs:
260
- - df_1
261
- - df_2
262
- df_1:
263
- file: file_1
264
- idxvars:
265
- i: i_1
266
- j: j_1
267
- myvars:
268
- var: var
269
- df_2:
270
- file: file_2
271
- idxvars:
272
- i: i_2
273
- j: j_2
274
- myvars:
275
- var1: var
276
- merged_on: #list of variables to merge on
277
- - i
278
- - j
279
- final_index:
280
- - i
281
- - j
282
- #+end_src
283
-
284
- * 9. Hard-coded Case
285
-
286
- In some cases where dataframes require more complex logic than simple mappings, create a Python file named after the dataframe in the wave's _ folder (e.g., ~Malawi/2004-05/_/food_acquired.py~).
287
- And create a Makefile on its country level/_ directory (e.g. ~Malawi/_/Makefile~).
288
- The system will automatically generate the dataframe by running Makefile.
289
-
290
- Note: The reason why not just simply run the python file is becasue some data's python files have dependencies.
@@ -1,138 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: LSMS_Library
3
- Version: 0.2.9.dev0
4
- Summary: Abstraction layer for Living Standards Measurement Survey data
5
- License: CC-BY-4.0
6
- Author: Ethan Ligon
7
- Author-email: ligon@berkeley.edu
8
- Requires-Python: >=3.11, <4.0
9
- Classifier: License :: Other/Proprietary License
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.11
12
- Classifier: Programming Language :: Python :: 3.12
13
- Classifier: Programming Language :: Python :: 3.13
14
- Requires-Dist: CFEDemands (>=0.7.0)
15
- Requires-Dist: PyYAML
16
- Requires-Dist: dvc[s3] (>=3.61.0,<4.0.0)
17
- Requires-Dist: ligonlibrary (>=0.1.1,<0.2.0)
18
- Requires-Dist: lsms (>=0.4.7,<0.5.0)
19
- Requires-Dist: openai (>=1.99.5,<2.0.0)
20
- Requires-Dist: pandas (>=2.2,<3.0)
21
- Requires-Dist: pyarrow (>=21.0.0,<22.0.0)
22
- Requires-Dist: pyreadstat (>=1.3.0,<2.0.0)
23
- Requires-Dist: scikit-learn (>=1.7.0,<2.0.0)
24
- Requires-Dist: xarray (>=2025.7.1,<2026.0.0)
25
- Description-Content-Type: text/plain
26
-
27
- * Streaming dvc files
28
- A =dvc pull= will download dvc files to your local repository.
29
- But this may not be the best way to proceed! In particular, =dvc=
30
- offers an api which permits one to "stream" or cache files, leaving
31
- your storage local to the working repository free of big data
32
- files.
33
-
34
- To illustrate,
35
- #+begin_src python
36
- import dvc.api
37
- import pandas as pd
38
-
39
- with dvc.api.open('BigRemoteFile.dta',mode='rb') as dta:
40
- df = pd.read_stata(dta)
41
- #+end_src
42
- This will result in a =pandas.DataFrame= in RAM, but will use no
43
- additional disk (except that, depending on what's being used as the
44
- dvc store, the file may actually be stored in =.dvc/cache=; this
45
- cache can be cleared with =dvc gc=).
46
-
47
- ** Pulling dvc files
48
- If you need the actual file instead of a "stream" you can instead
49
- "pull" the dvc files, using
50
- #+begin_src sh
51
- dvc pull
52
- #+end_src
53
- and files should be added from the remote dvc data store to your
54
- working repository.
55
-
56
- * Adding New Data
57
- ** Additional S3 Credentials
58
- Write access to the remote s3 repository requires additional credentials; contact =ligon@berkeley.edu= to obtain these.
59
-
60
- ** Procedure to Add Data
61
- To add a new LSMS-style survey to the repo, you'll follow the
62
- following steps. Here we give the example of adding a 2015--16
63
- survey from Uganda, obtained from
64
- https://microdata.worldbank.org/index.php/catalog/3460. The same
65
- steps should work for you /mutatis mutandis/:
66
-
67
- 1. Create a directory corresponding to the country or area; e.g.,
68
- #+begin_src sh
69
- mkdir Uganda
70
- #+end_src
71
- 2. Create a /sub/-directory indicating the time period for the
72
- survey; e.g.,
73
- #+begin_src sh
74
- mkdir Uganda/2015-16
75
- #+end_src
76
- 3. Create a =Documentation= sub-directory for each survey; e.g.,
77
- #+begin_src sh
78
- mkdir Uganda/2015-16/Documentation
79
- #+end_src
80
- In this directory include the following files:
81
- - SOURCE :: A text file giving both a url (if available) and
82
- citation information for the dataset.
83
- - LICENSE :: A text file containing a description of the license
84
- or other terms under which you've obtained the data.
85
- 4. Add other documentation useful for understanding the data to the
86
- =Documentation= sub-directory.
87
-
88
- 5. Add all the contents of the =Documentation= folder to the =git= repo;
89
- e.g.,
90
- #+begin_src sh
91
- cd ./Uganda/2015-16/Documentation
92
- git add .
93
- git commit -m"Add Uganda 2015-16 documentation to repo."
94
- git push
95
- #+end_src
96
-
97
- 6. Create a =Data= sub-directory for each survey; e.g.,
98
- #+begin_src sh
99
- mkdir Uganda/2015-16/Data
100
- #+end_src
101
-
102
- 7. Obtain a copy of the data you're interested in, perhaps as a zip
103
- file or other archive. Store this in some temporary place, and
104
- unzip (or whatever) the files into the relevant Country/Year/Data
105
- directory, taking care to preserve any useful directory structure
106
- in the archive. E.g.,
107
- #+begin_src sh
108
- cd Uganda/2015-16 && unzip -j /tmp/UGA_2015_UNPS_v01_M_STATA8.zip
109
- #+end_src
110
- 8. Add the data you've unarchived to =dvc=, then add the /pointers/
111
- (i.e., files with a .dvc extension to git). For the Uganda case we assume that
112
- all the relevant data comes in the form of =stata= *.dta files,
113
- since this is what we downloaded from the World Bank. For example,
114
- #+begin_src sh
115
- cd ../Data
116
- dvc add *.dta
117
- git commit -m"Add Uganda/2015-16/Data/*.dta files to dvc store."
118
- git pull && git push
119
- #+end_src
120
- 9. Push the data files to the dvc store. Make sure you have good
121
- internet connection! Then a simple
122
- #+begin_src sh
123
- dvc push
124
- #+end_src
125
- will copy the data to the remote data store. NB: If this is the
126
- first time you've done this for this repository, then you'll
127
- first need to jump through some simple hoops to authenticate with
128
- gdrive.
129
- 10. With the files pushed to the dvc store, you won't need them
130
- locally anymore, so you can do something like
131
- #+begin_src sh
132
- cd ../Data && rm *.dta
133
- #+end_src
134
- or (if you have a more complex directory structure) perhaps
135
- #+begin_src sh
136
- find ../Data -name \*.dta -exec rm \{\} \;
137
- #+end_src
138
-